【发布时间】:2017-05-06 19:12:36
【问题描述】:
嗨,我想在屏幕上看到用户的所有信息,但我无法在 mongodb 中添加用户。 Locations Schema中的用户位置信息。但我不知道如何获取位置信息(即城市,城镇......)来输入UserSchema。这是我的代码:
用户架构:
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' }
});
Create User Function :
this.createUser = function (req, res, next) {
var lok=new Location({il:req.params.il,ilce:req.params.ilce});
lok.save(function(err){
var user=new User({name:req.params.name,surname:req.params.surname,tel:req.params.tel,age:req.params.age,mevki_id:req.params.mevki_id,location_id:user});
user.save(function(err){
user.location_id=lok;
});
return res.send({})
});
}
谢谢:)
【问题讨论】:
标签: javascript node.js mongodb mongoose schema