update query

11 views
Skip to first unread message

Emmanuel VINET

unread,
Apr 25, 2012, 9:14:53 AM4/25/12
to mongod...@googlegroups.com
Hi,

Is it possible to use an attribute of the current document to update the value of an other like this :
db.collection.update({_id : {$exists : true}},
                      {$set : {"dt.y" : new Date(this.TMST * 1000).getFullYear(),
                                      "dt.m" : new Date(this.TMST * 1000).getMonth(),
                                      "dt.d": new Date(this.TMST * 1000).getDay(),
                                      "dt.h" : new Date(this.TMST * 1000).getHours()}},
                      false,true);

TMST is a special timestamp.
Thanks.
Emmanuel

Scott Hernandez

unread,
Apr 25, 2012, 9:18:42 AM4/25/12
to mongod...@googlegroups.com
You will need to get the document first, then apply the logic for each
document in a single update. There are no update expressions on the
server like this.

You may want to watch/vote for this issue:
https://jira.mongodb.org/browse/SERVER-458

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mongodb-user/-/ciKsgwkoZV0J.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.

Emmanuel VINET

unread,
Apr 25, 2012, 9:21:27 AM4/25/12
to mongod...@googlegroups.com
thanks for your response.
I'll do it an other way.
Emmanuel
Reply all
Reply to author
Forward
0 new messages