php - MongoDb Update only one value from array -


i have collection in mongodb looks this.

"_id" : objectid("554c5397ccfff21e103c9869"), "name" : "test", "color" : [     "552ced22ccfff2d8183c986a_jellow",     "551fdd24ccfff2362e3c9869_test" ], "updated_at" : isodate("2015-05-08t06:11:35.303z"), "created_at" : isodate("2015-05-08t06:11:35.303z") 

i want update 1 value in array color when try update array removes values color array , replaces new value. here code. (i using jessenger mongodb package laravel)

$query->where($field,'regexp','/^('.$id.')_.*/')->update([$field=>$id.'_'.$name]); 

how should it.??

what wanna is, either change schema {key: value} pair , follow tutorial, sort out problem. or can values color array , replace new value , update document (i not go coz dirty approach!).

edit

hey bud! founded this, on jenssenger docs:


push

add items array.

db::collection('users')->where('name', 'john')->push('items', 'boots'); db::collection('users')->where('name', 'john')->push('messages', array('from' => 'jane doe', 'message' => 'hi john')); 

if don't want duplicate items, set third parameter true:

db::collection('users')->where('name', 'john')->push('items', 'boots', true); 

pull

remove item array.

db::collection('users')->where('name', 'john')->pull('items', 'boots'); db::collection('users')->where('name', 'john')->pull('messages', array('from' => 'jane doe', 'message' => 'hi john')); 

Comments