mongodb - Mongo DB, PHP add or update a field in a document -


i have following document:

{    "_id": objectid("5241f1d79b7e7aed05000000"),    "description": {      "nl": "hallo",      "en": "hello"     },   "name": "marc" } 

now need update update 1 existing field or add new field description. in php use update function mongo , following code:

$new_data = array(     '$set' => array(     "description" => array(          "de" => "hallo"        )     ) ); 

what removes other fields , insert "de" field. tried replacing $set $push (which thought made this) no result $setoninsert not anything.

how can solve problem can either add new field (if not exist) or update if exist.

thanks

just make update

{$set: {"description.de": "hello"}} 

i guess in code be:

$new_data = array(   '$set' => array(     "description.de" => "hallo"   ) ); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -