Assume the collection name "groups"
Sample Document:
{
|
"_id" : ObjectId("597620fcba76f211586c9203"),
|
"task" : {
|
"taskId" : ObjectId("597620fcba76f211586c9402"),
|
"hasTasks" : true
|
}
|
}
|
Failing Query:
db.getCollection('groups').find({task: { hasTasks: true, taskId: ObjectId("597620fcba76f211586c9402")}, _id: ObjectId("597620fcba76f211586c9203") })
|
|
Passing Query:
db.getCollection('groups').find({task: { taskId: ObjectId("597620fcba76f211586c9402"), hasTasks: true, }, _id: ObjectId("597620fcba76f211586c9203") })
|
|
As you can see, if the order of the query fields in the sub-document (viz. task) does not match the order in which it exists in the document, query does not return any results.