[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.

see
http://groups.google.com/group/mongodb-user/browse_thread/thread/58951cdf45c57e38/a37bfe469292b9fc?hl=en&lnk=gst&q=obtain+index#a37bfe469292b9fc



 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 SERVER-631
http://github.com/mongodb/mongo/commit/9172d692cd57624902443e93c3b571734b97d23a

Comment by auto [ 09/Mar/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: use .$ instead of .~ for SERVER-631
http://github.com/mongodb/mongo/commit/bca88a8001e471b85af0787a39300d3ae2fa29f8

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 ... }

) SERVER-631
http://github.com/mongodb/mongo/commit/d3da0d7bbc6ace93df2eecdc3d5862b8e5cac154

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":
{ "members.name":

{ "from":"Freddy","to":"Fred" }

}
}

{ "$update":
{ "members.name":

{ "from":/^Fred/,"to":"Fred" }

}
}

{ "$updateIn":
{ "members.name":

{ "from":["Freddy","Frank"],"to":"Fred" }

}
}

Using example documents from the google groups thread.

Generated at Thu Feb 08 02:54:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.