Hi!
I have a collection which holds _id (indexed field) that starts with null character and also has some of them in the middle.
I noticed that when I try to $regex
a prefix that starts with a null character, the query looks at all the keys in the collection.
Example query (some names changed for simplicity, but the start and end of the regex is the same)
db.collection_example.find({_id: {$regex: '^\\000versions\\000backup1,\\000vaa.*'}).explain("executionStats")
I get: "totalKeysExamined" : 6431140
(this is the total number of documents in the collection)
When I try the same query but omit the first null character I get the following:
db.collection_example.find({_id: {$regex: '^versions\\000backup1,\\000vaa.*'}).explain("executionStats")
I get: "totalKeysExamined" : 0
(of course there are no documents that start with this name, but the query still returns pretty fast and does not try the whole collection)
Do you think my query is wrong for this case, or does mongo has some issue with indexing and searching values that start with a null character?
Thanks for any reply!