php - Update item inside a mongodb object -
i'm trying save()
record inside object. problem mongocursor()-errors
or unexpected 'array' (t_array)
. instance:
this mongodb-collection:
[ { "id": "dfk15ale12", "keys": { "gcm_key": "abc", "app_secret": "123" } }
]
i want update gcm_key
inside keys
, php code:
$db->apps->save( array("_id" => $update['_id']) array("$push" => 'keys.gcm_android' => $gcm_android); );
this gives me following error:
parse error: syntax error, unexpected 'array' (t_array) in c:\xampp\htdocs\api\update.php on line 3
i have googled , looked here on stack find answers, , i've found nothing. maybe i've missed something. don't know, correct mongodb cursor , easiest way save()
gcm_key
?
the operation seem want update
$db->apps->update( array('_id' => $update['_id']), array('$push' => array('keys.gcm_android' => $gcm_android)) );
but un-clear want end result be. produce following:
{ "_id" : objectid("532aa3d15fcd8ecb9ae23567"), "id" : "dfk15ale12", "keys" : { "gcm_key" : "abc", "app_secret" : "123", "gcm_android" : [ 123 ] } }
assuming had value 123
in $gcm_android
variable. if have array @ $pushall.
if looking add property keys use $set:
$db->apps->update( array('_id' => $update['_id']), array('set' => array('keys.gcm_android' => $gcm_android)) );
where result:
{ "_id" : objectid("532aa3d15fcd8ecb9ae23567"), "id" : "dfk15ale12", "keys" : { "gcm_key" : "abc", "app_secret" : "123", "gcm_android" : 123 } }
Comments
Post a Comment