请教一个Mongoose问题
UserSchema = new Schema({
name: String,
password: String
})
var User = mongoose.model(‘User’, UserSchema)
PostSchema = new Schema({
title: String,
body: String,
user: {type : Schema.ObjectId, ref : ‘User’}
});
var Post = mongoose.model(‘Post’, PostSchema);
app.get(’/posts’, function(req, res, next){
var user = new User({name: ‘lentg’, password: ‘123’});
var post = new Post({title: ‘hello’, body: ‘world’, user: user});
console.log(post.user); 这里输出为的用户是user._id, 在别的例子中输出的都是 user对象,想问一下这是怎么回事啊?
});
2 回复
如果不populate的话就是只输出子文档的_id
谢谢,了解了。