MongoDB:我如何使用PHP(而不是对象)插入javascript数组?

$update = $col->update(array('_id' => 'test'), array('$push' => array('friends' => 1)), array('safe' => true, 'upsert' => true));
$test = $col->findOne(array('_id' => 'test'));
debug(compact('update', 'test'));

Does not work as expected.

I get (checking via RockMongo) :

{
   "_id": "test",
   "friends": {
     "0": 1 
   } 
}

I want/expect to have this :

{
   "_id": "test",
   "friends": [
     1 
   ] 
}

Any ideas ? Thanks !

I spent a good amount of time a while back troubleshooting why my data was getting inserted wrongly only to find out that RockMongo doesn't show the data correctly.

It's belive its because RockMongo isn't really showing the data as a Mongo document, but instead as PHP.

I found this to differ for a couple of different datatypes between firefox and chrome for some reason ... arrays, dates, MongoID's

But in the end, I did a find() on the command line and it was correct.

I wouldn't trust what RockMongo is telling you, see an example below.

Also is there a reason you need to use "safe" ?

Actual Data

enter image description here

What RockMongo says (wrong)

enter image description here