I have a collection with objects like this
{
    "_id" : ObjectId("5742be02289512cf98bf63e3"),
    "name" : "test1",
    "attributes" : [ 
        {
            "name" : "x",
            "color" : "0xd79c9c",
            "_id" : ObjectId("5742be02289512cf98bf63e8")
        }, 
        {
            "name" : "y",
            "color" : "0xd79c9c",
            "_id" : ObjectId("5742be02289512cf98bf63e7")
        }, 
        {
            "name" : "z",
            "color" : "0xd79c9c",
            "_id" : ObjectId("5742be02289512cf98bf63e6")
        }
    ],
    "__v" : 6
}
And I want to update all documents, and set for each attribute new field. So I want to run a single query to update all documents at once. I think, this query will do
db.spaces.update({}, { $set: { "attributes.0.weight": 2 } }, {multi: true})
But when I run this query, I get an error:
"code" : 16837,
"errmsg" : "The positional operator did not find the match needed from the query. Unexpanded update: attributes.$.weight"
I can't understand why. Please help
 
     
     
     
    