I have two schemas: Pages and Posts.
var pageSchema = new Schema({
commented_times: {
type: Number,
default: 0
},
posts: {
type: Schema.Types.ObjectId,
ref: 'Post'
}
});
var postSchema = new Schema({
page: [{
type: Schema.Types.ObjectId,
ref: 'Page'
}]
});
I want to get all Posts, where commented_times in Page is lover than 3, how do I do that?
I tried the following, but it is not working.
return Post.find({}).populate({
path: 'page',
match: {
commented_times: {
$lt: 3
}
},
}).sort({
rating: -1
}).limit(5);