push new value to mongodb inner array - mongodb/php

Posted by Rizky Ramadhan on Stack Overflow See other posts from Stack Overflow or by Rizky Ramadhan
Published on 2011-01-09T08:41:45Z Indexed on 2011/01/09 10:53 UTC
Read the original article Hit count: 694

Filed under:
|

hi

i have this document in mongo:

{
   "_id": ObjectId("4d0b9c7a8b012fe287547157"),
   "done_by": ["1"]
}

and i want to add another value to "done_by" field, so my expected document will be::

{
   "_id": ObjectId("4d0b9c7a8b012fe287547157"),
   "done_by": ["1","2","3"]
}

i try this:

$conn = new Mongo();
$q = $conn->server->gameQueue;
$id = new MongoId("4d0b9c7a8b012fe287547157");
$q->update(array("_id"=>$id),array('$push' => array("done_by","2")));

but nothing happens, anyone know how to do this?

© Stack Overflow or respective owner

Related posts about php

Related posts about mongodb