Update Problem

30 views
Skip to first unread message

JPM

unread,
May 4, 2012, 8:35:22 AM5/4/12
to mongodb-user
Hi All,

I used the below command to update the "pCity" for candidate ID = 1.
It updated the record successfully, but elements positioning in the
documents has been disturbed.

db.candidates.update({"candidateID":1},{$set:{"pCity":"Mohali"}})

How can I update the pCity only for candidate = 1 without changes of
position of object elements? Please suggest me.

Adam C

unread,
May 4, 2012, 9:19:25 AM5/4/12
to mongod...@googlegroups.com
The position of elements within a document is not guaranteed.  You should not rely on it:


If it is an in-place update, not requiring a move (i.e. the document does not grow) this is less likely, but again, don't rely on it.  If you need a particular order enforced, enforce it on the client side code.

Adam.

Jay Prakash Mishra

unread,
May 5, 2012, 1:37:14 AM5/5/12
to mongod...@googlegroups.com
Thanks for reply.
what would be the best way to restrict the particular order of elements at client side while updating? I am using PHP scripts.

--
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/-/3m5hjiKmNM0J.

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.



--
Thanks & Regards
 Jay Prakash | Software Engineer
 M.  N. - 9953477708
 


Adam C

unread,
Feb 9, 2013, 5:20:27 PM2/9/13
to mongod...@googlegroups.com
I'm not a PHP dev, but as far as I understand it PHP does not support ordering automatically, so I think you may have to enforce this yourself.  If you have a specific implementation need, then it may be worth asking a more detailed question here (i.e. with the problem you are trying to solve in PHP) or perhaps give StackOverflow a shot as an alternative.

Adam
Reply all
Reply to author
Forward
0 new messages