I have an odd issue querying mongo.. I insert a bunch of records like this;
{
"_id" : "1f0aad54-85ef-446c-a02b-76bb0235e49c",
"internalId" : new BinData(3, "VP0LH++FbESgK3a7AjXknA=="),
"Data" : [
["otherId", "5e3b3293-ec93-469a-ba46-101a1feb1155"],
["test", "test"],
["test2", "test2"]
]
}
Then I do a simple query;
db.testCollection.find("Data.otherId" : "5e3b3293-ec93-469a-ba46-101a1feb1155")
The otherId is a .net guid.ToString() -- several random ones obviously.. Sometimes these return. Sometimes they do not. db.find() shows them, but querying for it explicitly seems to return 0 rows at random.
I can't explain why these will intermittently fail to be found by the query.. I've tested this in my sharded cluster and on my local instance that's just vanilla out of the box.
Has anyone encountered this?
You're using the wrong selector. If your data would be:
{
"_id" : "1f0aad54-85ef-446c-a02b-76bb0235e49c",
"internalId" : new BinData(3, "VP0LH++FbESgK3a7AjXknA=="),
"Data" : {
"otherId" "5e3b3293-ec93-469a-ba46-101a1feb1155",
"test": "test",
"test2": "test2"
}
}
that selector would be correct but you've got arrays so you should use this selector:
db.testCollection.find({"Data.0" : ["otherId","5e3b3293-ec93-469a-ba46-101a1feb1155"]})
(I just tested it)