Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
None
-
None
Description
Our documentation says that positional projection operator returns The first element if no query condition is specified for the array (Starting in MongoDB 4.4).
It looks like we do not have such behaviour implemented:
$ mongod --version
|
db version v4.4.1
|
Build Info: {
|
"version": "4.4.1",
|
"gitVersion": "ad91a93a5a31e175f5cbf8c69561e788bbc55ce1",
|
"modules": [],
|
"allocator": "system",
|
"environment": {
|
"distarch": "x86_64",
|
"target_arch": "x86_64"
|
}
|
}
|
|
|
> db.test.find()
|
{ "_id" : ObjectId("5ff47546d0e2d9910975e0cb"), "x" : 1, "a" : [ 1, 2, 3 ] }
|
|
|
> db.test.find({}, {'a.$': 1})
|
Error: error: {
|
"ok" : 0,
|
"errmsg" : "positional operator '.$' couldn't find a matching element in the array",
|
"code" : 51246,
|
"codeName" : "Location51246"
|
}
|
|
|
> db.test.find({x: 1}, {'a.$': 1})
|
Error: error: {
|
"ok" : 0,
|
"errmsg" : "positional operator '.$' couldn't find a matching element in the array",
|
"code" : 51246,
|
"codeName" : "Location51246"
|
}
|
In queries above we do not specify query condition for the array. The query fails instead of returning the first element of array in field a.