On Nov 26, 11:21 am, Dwight Merriman <
dwi...@10gen.com> wrote:
> one workaround would be to first pop the value - which will do nothing if
> not present - and then push it, as two updates. this should still be quite
> fast, and there is no client/server turnaround in between. the only
> possible isseu is the operation isn't atomic - there is a short window
> between the updates where 'mini_cooper' would be missing from the POV of
> another reader (very unlikely). if that is a concern use db.eval().
>
> On Thu, Nov 26, 2009 at 10:43 AM, sdotsen <
samnang....@gmail.com> wrote:
> > Trying to update the "tags" field but I can't get it to work
> > correctly. I only want to insert the value if it doesn't exist.
> > I'm running the latest version of the php driver.
>
> > {"_id" : ObjectId( "4b0ca6b04490c046db88a1a4") , "username" :
> > "james" , "tags" :
> > ["apple","blueberry","snorkling","basketball","mini_cooper"]}
>
> > I've tried the following which seems to not have added "mini_cooper"
> > but if I change it to something else (i.e. "bmw"), it doesn't add.
>
> > $collection->update(array("username" => "james"), array('$push' =>
> > array("tags" => "mini_cooper"),true));
> > $collection->update(array("username" => "james"), array('$push' =>
> > array("tags" => "mini_cooper")), true);
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to
mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to