-
-
Save ismell/9ae5a9798ae82a1a85de to your computer and use it in GitHub Desktop.
Mongo 2.6 positional operator matching incorrect sub document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.bug.save({ | |
"_id" : ObjectId("53e29d8473636f0664000000"), | |
"dimensions" : [ | |
{ | |
"_id" : ObjectId("53e29d8473636f0664010000"), | |
"values" : [] | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640b0000"), | |
"values": [] | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640c0000"), | |
"values" : [ | |
{ | |
"_id" : ObjectId("53e29d8473636f06640e0000"), | |
"weight" : 12 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640f0000"), | |
"weight" : 11 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664100000"), | |
"weight" : 3 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664110000"), | |
"weight" : 17 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664120000"), | |
"weight" : 35 | |
} | |
] | |
}, | |
] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id" : ObjectId("53e29d8473636f0664000000"), | |
"dimensions" : [ | |
{ | |
"_id" : ObjectId("53e29d8473636f0664010000"), | |
"values" : [ ] | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640b0000"), | |
"values" : [ ] | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640c0000"), | |
"values" : [ | |
{ | |
"_id" : ObjectId("53e29d8473636f06640e0000"), | |
"weight" : 0 // Correct | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640f0000"), | |
"weight" : 11 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664100000"), | |
"weight" : 3 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664110000"), | |
"weight" : 17 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664120000"), | |
"weight" : 35 | |
} | |
] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id" : ObjectId("53e29d8473636f0664000000"), | |
"dimensions" : [ | |
{ | |
"_id" : ObjectId("53e29d8473636f0664010000"), | |
"values" : [ ] | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640b0000"), | |
"values" : [ ] | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640c0000"), | |
"values" : [ | |
{ | |
"_id" : ObjectId("53e29d8473636f06640e0000"), | |
"weight" : 12 // this value should have been updated | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f06640f0000"), | |
"weight" : 11 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664100000"), | |
"weight" : 0 // Incorrect sub document selected | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664110000"), | |
"weight" : 17 | |
}, | |
{ | |
"_id" : ObjectId("53e29d8473636f0664120000"), | |
"weight" : 35 | |
} | |
] | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.bug.update({ | |
"_id":ObjectId('53e29d8473636f0664000000'), | |
"dimensions._id":ObjectId('53e29d8473636f06640c0000'), | |
"dimensions.2.values._id":ObjectId('53e29d8473636f06640e0000') | |
},{ | |
"$set":{ | |
"dimensions.2.values.$.weight": 0 | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.bug.find({ | |
"_id":ObjectId('53e29d8473636f0664000000'), | |
"dimensions._id":ObjectId('53e29d8473636f06640c0000'), | |
"dimensions.2.values._id":ObjectId('53e29d8473636f06640e0000') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For mongodb 2.6 it looks like this should work...
Indeed it's a complete different kind of updating :-(