CNode

请教一个Mongoose问题

Llentg发布于12 年前最后回复12 年前2 回复4193 浏览0 收藏

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)

S
showen#1·12 年前

如果不populate的话就是只输出子文档的_id

参与回复
登录后即可参与回复。登录