Created
March 24, 2010 20:19
-
-
Save durran/342738 to your computer and use it in GitHub Desktop.
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
# Problem: Given the following document in the database, I want to update | |
# Dave Gahan's second prescription for Dilaudid from a quantity of 45 to | |
# a quantity of 30. | |
{ "_id" : 1 | |
"name" : "Dave Gahan" | |
"medications" : [ | |
{ "id" : 23, | |
"name" : "Dilaudid", | |
"type" : "Rx", | |
"prescriptions" : [ | |
{ "id" : 13, | |
"quantity" : 60, | |
"started" : 2009-01-01 | |
}, | |
{ "id" : 77, | |
"quantity" : 45, | |
"started" : 2009-02-01 | |
} | |
] | |
}, | |
{ "id" : 41, | |
"name" : "Oxycodone", | |
"type" : "Rx" | |
} | |
] | |
} | |
# First try was using 1.3.4 $ positional locator... These do not find the | |
# document embedded multiple levels: | |
collection.update( | |
{ "_id" : 1, "medications._id" : 23, "medications.prescriptions._id" : 77 }, | |
{ $set : { "medications.prescriptions.$.quantity" : 30 } }, | |
false, | |
true | |
) | |
collection.update( | |
{ "_id" : 1, "medications._id" : 23, "medications.prescriptions._id" : 77 }, | |
{ $set : { "medications.$.prescriptions.$.quantity" : 30 } }, | |
false, | |
true | |
) | |
# What I would like is to be able to match on mutliples, given a syntax like the following: | |
collection.update( | |
{ "_id" : 1, "medications._id" : 23, "medications.prescriptions._id" : 77 }, | |
{ $set : { "medications.$0.prescriptions.$1.quantity" : 30 } }, | |
false, | |
true | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is there any update for this?