I am working on a query to display user posts based on the country selected by the visitor. However, my current approach is not working as expected.
Here is what I have tried so far:
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, this code snippet is not yielding the desired results.
Can anyone suggest an alternative way to achieve this?
EDIT:
Below is the schema for the Posts:
var postsSchema = new mongoose.Schema({
_creator: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
text: { type: String, default: '' },
created_at: Date
});