0
別のエラーはありませんが、私はちょっとひとつ知りたいのですが。ユーザースキーマオブジェクトの参照を使用する方法_id意味location_id新しいユーザーを追加するときの使い方。nodejsで参照を与えるオブジェクトIDの使用方法mongodb
ユーザー・スキーマ:
var userSchema = Mongoose.Schema({
name:{type: String,require:true},
surname: {type: String,require:true},
tel: {type: String,require:true},
age: {type: String,require:true},
mevki_id: {type: String,require:true},
location_id: { type: Mongoose.Schema.Types.ObjectId, ref: 'locations' }
});
場所スキーマ:
var LocationSchema = Mongoose.Schema ({
il: {type: String, require:true},
ilce: {type:String, require:true}
});
UserControllerで - 私はここで
this.createUser = function(req, res) {
var la=new Location({il:'istanbul',ilce:'camlica',location_id:la._id}).save(function (err) {
if (err) return handleError(err);
});
var user = new User({
name:'akif',surname:'demirezen',tel:'544525',age:'45',mevki_id:'2',
}).save(function (err) {
if (err) return handleError(err);
res.send(JSON.stringify(job));
});
}
私は本当に私がこのres.send(JSON.stringify(user))になると思います。 – MAD