M001 - CH4 - Lab 1: Array Operators - Order of elements

For finding the answer to the name of the property that has exactly 50 reviews and accommodates more than 6 people, I found that the order in which I typed the fields made a difference in the answer. Using an implicit AND, if I type { “accommodates”:{"$gt":6}},{“reviews”:{"$size":50}} I get many documents (as if it ignores the second filter), but if I type {“reviews”:{"$size":50},“accommodates”:{"$gt":6}} I get the one document.

In other languages I have never seen that the order of the fields in an AND clause makes any difference. Is this something peculiar to MongoDB or am I doing something wrong?

I have found the answer. My mistake was the use of extra curly braces:
db.listingsAndReviews.find({ “accommodates”:{"$gt":6}} , {“reviews”:{"$size":50}}) //yields 452 documents
Remove these----------------------------------------------^ ^
db.listingsAndReviews.find({ “accommodates”:{"$gt":6}, “reviews”:{"$size":50}}) //yields 1 document

2 Likes