Details
-
Bug
-
Resolution: Cannot Reproduce
-
Major - P3
-
None
-
3.6.2
-
None
-
ALL
Description
Hello,
I'm having major problems getting the new $[<identifier] operator to work as expected in mongodb v. 3.6.2.
I have a collection containing the following type of documents:
{
|
...,
|
"documents": [
|
{
|
"id": "1234",
|
"status": "UNTOUCHED"
|
},
|
...
|
]
|
}
|
I'm executing the following update stmt:
db.mycollection.update(
|
{ },
|
{ $set: { "documents.$[e].status" : "TOUCHED" } },
|
{ arrayFilters: [ { "e.id": "1234" } ] }
|
)
|
And I get the following result:
code: 16837
|
msg: cannot use the part (documents of documents.$[e].status) to traverse the element...
|
I thought it might be my mongodb installation which was somehow corrupted so I did the following to verify that this was not the issue:
1) Went to Mongo Atlas and create a whole new cluster with version 3.6.2 of mongodb.
2) Create a collection, "students2", containing the following two documents:
{
|
"_id" : 1,
|
"grades" : [
|
{ "grade" : 80, "mean" : 75, "std" : 6 },
|
{ "grade" : 85, "mean" : 90, "std" : 4 },
|
{ "grade" : 85, "mean" : 85, "std" : 6 }
|
]
|
}
|
{
|
"_id" : 2,
|
"grades" : [
|
{ "grade" : 90, "mean" : 75, "std" : 6 },
|
{ "grade" : 87, "mean" : 90, "std" : 3 },
|
{ "grade" : 85, "mean" : 85, "std" : 4 }
|
]
|
}
|
3) Executed the following command:
db.students2.update(
|
{ },
|
{ $set: { "grades.$[elem].mean" : 100 } },
|
{
|
multi: true,
|
arrayFilters: [ { "elem.grade": { $gte: 85 } } ]
|
}
|
)
|
This resulted in a new error:
code: 2
|
msg: No array filter found for identifier 'elem' in path 'grades.$[elem].mean'
|
Pease note that the above have been taking directly from https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/#update-all-documents-that-match-arrayfilters-in-an-array without modifying it the slightest.