I want to query the DB and return a set of documents where the selected nested field is equal to true
. As a contrived example: Let's assume I have Facebook users, and their data is stored with this format.
const UserSchema = new Schema({
name: String,
age: Number,
permissions: {
allow_comments: Boolean,
allow_likes: Boolean,
allow_shares: Boolean
}
})
And I want to return all the users who have permissions.allow_likes
set to true
. Notice, it's not a full-on sub-document, it's just an object with some data in it (maybe that's bad, idk).
I looked around and didn't find much. So then, I tried this:
UserModel.find({permissions: {allow_likes: {$eq: true}}})
.then(users => console.log(users)); // returns [];
Thanks in advance!