Sorry for reposting. I accidentally deleted my old post and couldn’t find the way to undo that.
I have a nullable string field, and when the value is not null, it needs to unique.
I created the index using pymongo like this
f = "item_number"
my_coll.create_index(
[(f, 1)], unique=True, name=f"unique_{f}",
partialFilterExpression={f: {"$exists": True, "$type": "string"}},
)
The index could be created successfully, and I inserted documents to the collection.
When I tried to search for an item_number, COLLSCAN is always used.
My search is like this:
db.my_coll.find({item_number: "2ae9dc2f-2ff6-4239-9b7a-cccb757fc912"}).explain("executionStats")
The execution plan is attached. (
mongo_plan.json (2.5 KB)
)
Have I done something wrong? Should I expect IXSCAN to be used for such search?
Thank you very much.