I have a query that get user posts and I wish to show only the posts of the Country selected by visitor.
So far I'm trying to do something like this:
var country = req.query.country || req.session.country || { $ne: '' };
Posts.find({})
.populate('_creator')
.where('_creator.country').equals(country)
.exec(function(err, posts) {
console.log(posts);
});
Unfortunately it doesn't work.
How can I have a query similar to this?
EDIT:
This is the Posts Schema:
var postsSchema = new mongoose.Schema({
_creator: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
text: { type: String, default: '' },
created_at: Date
});