SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

Updating Multiple Properties through POST/PATCH #172

Closed genxlogics closed 7 years ago

genxlogics commented 7 years ago

@ujibang , i am trying to set the multiple properties of a document through POST as below

POST /transactional/tempreq { "_id":"1" "$set":{"prop1":"val111","prop2":"val211"} }

what it is doing is that it removes all other existing properties of the document. so no new document has only two properties.

when i use PATCH it just updates something else at i dont know where

PATCH /transactional/tempreq { { "_id":"1", "$set":{"prop1":"val111","prop2":"val211"} } }

i need to update multiple properties and keep other things intact. please help !!

ujibang commented 7 years ago

Hi @genxlogics

PATCH is the verb to use to perform a partial update

However with your second request you are patching the collection resource (identified by the URI /transactional/tempreq). Note that RESTHeart manages properties for dbs and collections (have a look at this documentation page for a quick reference).

To patch your document

PATCH /transactional/tempreq/1

{
 "prop1":"val111",
 "prop2":"val211"
}

If the _id is a number, you need to pass the id_type query parameter (not needed for strings and ObjectId types)

PATCH /transactional/tempreq/1?id_type=number

the $set operator is optional. For instance the following request sets a and b and unsets c

PATCH /transactional/tempreq/1

{
 "a":1,
 "b":2,
 "$unset": {"c: ""}
}
mkjsix commented 7 years ago

Hi @genxlogics Did you solve your issue? I'm closing this now, feel free to re-open in case.