[ad_1]
Stumbled on a kinda weird behavior. so I asked here to hear more about it.
Sample Data:
// code : 15,25,35
db.getCollection('test_data').insertOne({
"foo" : "bar",
"tags" : [
{
"code" : 15
},
{
"code" : 25
},
{
"code" : 35,
"name" : "test"
}
],
});
use-case query: fetch records with tags.code = 23
, this is a simplified form of the actual query
db.getCollection('test_data').find({"tags.code" : { "$gt" : 22, "$lt":24 }});
Expected Result: no result
Actual Result: returns the inserted record
I expected the use-case query to work just as this query :
db.getCollection('test_data').find({
"tags" : {
"$elemMatch" : {"code" : { "$gt" : 22, "$lt":24 }}
}
});
MongoDB Version :
$ mongo --version
MongoDB shell version v4.4.14
Build Info: {
"version": "4.4.14",
"gitVersion": "0b0843af97c3ec9d2c0995152d96d2aad725aab7",
"openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020",
"modules": [],
"allocator": "tcmalloc",
"environment": {
"distmod": "ubuntu2004",
"distarch": "x86_64",
"target_arch": "x86_64"
}
}
[ad_2]