[SERVER-631] add $ tilde operator for dynamic index entry Created: 12/Feb/10 Updated: 12/Jul/16 Resolved: 09/Mar/10 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 1.3.4 |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Dwight Merriman | Assignee: | Eliot Horowitz (Inactive) |
| Resolution: | Done | Votes: | 25 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
a way to change the value of items in the right array element, where element to match is based on some condition. perhaps this is not the most generalized form, nor the write name - to be discussed. |
| Comments |
| Comment by Dwight Merriman [ 10/Mar/10 ] |
|
http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positionaloperator |
| Comment by auto [ 09/Mar/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: turn tests back on for |
| Comment by auto [ 09/Mar/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: use .$ instead of .~ for |
| Comment by Eliot Horowitz (Inactive) [ 09/Mar/10 ] |
|
need to change to $ so we don't add another escape chacter |
| Comment by auto [ 06/Mar/10 ] |
|
Author: {'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}Message: array match value mod update( {a.x : 5 }, { a.~.y ... } ) |
| Comment by John Nunemaker [ 22/Feb/10 ] |
|
@Dwight Yep, the first one is what I mean. The problem with the second example is I don't know the index of the comment, so I can't do comments.0, I believe. |
| Comment by Dwight Merriman [ 22/Feb/10 ] |
|
@John assume you mean just update the whole sub-object? hopefully that would work as something like: t.update( {comments._id:...}, { $set : { "comments.~" : <fullnewobject> }}) I think somethign like this already works with the latest code: t.update( ..., { $set : { "comments.0" : { _id : 3, a : 3, b : 4, c : 5 }} } ) |
| Comment by John Nunemaker [ 16/Feb/10 ] |
|
It would also be nice to just update the whole object. update( {comments._id: ...}, {_id: ..., name: 'John', body: 'Pants on the ground', ...} We embed comments in posts, but also allow updating comment information by blog authors. Would be handy to just replace the whole matching object. We also do the same thing with Templates and Fields. Fields are embedded (array of hashes) and being able to update one field in place in the array would be great. |
| Comment by Eliot Horowitz (Inactive) [ 16/Feb/10 ] |
|
should work with $unset also |
| Comment by Dwight Merriman [ 12/Feb/10 ] |
|
we could do something like update( {members.name : "Freddy", ...}, { $set : { "members.~.name" : "Fred" }} ) here '~' means "the array element(s) that were matched by the query expression". one nice thing with this approach is it would work with $push, $inc, etc. |
| Comment by Colin Mollenhour [ 12/Feb/10 ] |
|
Syntax proposal: { "$update": } { "$update": } { "$updateIn": } Using example documents from the google groups thread. |