In our code, for convenience, we use queries such as
db.collection.find({ "field": { $in: array } })
even if it arraycontains only one element. We could rewrite it in this case just be
db.collection.find({ "field": "element" })
We thought that these queries would behave the same, but we noticed that with complex queries that contain statements $orand multiple fields, while explain()showing the same query plan for both cases, the actual execution of the queries quickly returns for a simple case , when used, $inis executed forever, because perhaps it uses different index scans.
Why didn't the mongodb query compiler turn $inwith one element into the same thing as $eq? And why does explain()it still show that they use the same index and select scans, while in fact query execution explicitly uses different plans?
source
share