我有場地,其中每個都有評論部分。每個評論都是一個Mongoose評論模式。每條評論都有一個創建者屬性,這是一個用戶模式。我正在嘗試查找特定用戶發佈的所有評論。我怎樣才能做到這一點?查詢Mongoose模式。嵌套評論
var VenueSchema = new mongoose.Schema({
comments: [{
type : mongoose.Schema.Types.ObjectId,
ref: 'Comment',
default: []
}]
},
{minimize: false});
var CommentSchema = new mongoose.Schema({
creator: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
}, {minimize: false});
var UserSchema = new mongoose.Schema({
token: String,
venues: [{ //in case we want users to save their favorite venues
type : mongoose.Schema.Types.ObjectId,
ref: 'Venue'
}]
});
我已經試過
Venue.find({
"comments.creator": "55f1fa1263877ed0067b78c0"
}, function(err, docs) {
console.log(docs);
res.send(docs);
})
但它返回一個空數組。 「55f1fa1263877ed0067b78c0」是樣本創建者_id。提前致謝!