Reputation: 11
When I query my MongoDB server with a filter using $all and an empty array I don't get any results.
I am using pymongo and when my query looks like this:
my_collection.find({"some_field": some_value, "array_field": {"$all": []}})
I don't get any result. If I change it to this:
my_collection.find({"some_field": some_value})
I do get the results I want.
Is this behavior as should be (and I should not send an $all filter if the array is empty)?
My reference is https://docs.mongodb.com/manual/reference/operator/query/all/
Thanks a lot.
Upvotes: 1
Views: 69
Reputation: 8834
$all
is used to query a list and will match when all items in your specified list match with items in the database list; you have no items in the all query, so the query makes no sense; I'm surprised it doesn't throw an error.
Upvotes: 1