Updating an entity object, Problem

n1ql
query

#1

If I have the following document for example:
{
“make”:“BMW”,
“make1”:“AUDI”
}

When I do an UPDATE query UPDATE Translations SET make2 = “MERCEDES” WHERE META().id = “CARS” , there is no problem with the query and make2 is added to the document.

When I do an UPDATE query UPDATE Translations SET make2.MODEL = “CLS”, make2.MODIFICATION = “500” WHERE META().id = "CARS"
The query returns “sucess”, but nothing is added. If make2 already exists everything is updated as expected, the problem only appears if the object does not exist.


#2

You are creating nested document with nested path if the path not exist or not object it will not create.

UPDATE Translations USE KEYS "CARS" SET make2 = {"MODEL":"CLS", "MODIFICATION":"500"} ;

OR

UPDATE Translations USE KEYS "CARS"
 SET make2 = CASE WHEN make2 IS MISSING THEN {} ELSE make2 END, 
         make2.MODEL = "CLS",
         make2.MODIFICATION = "5001" ;

#3

Here somebody answered it too: