0

I am using RESTHeart and MongoDB. I have multiple JSON objects and I want to update a particular object at a time with a REST call. I am following https://softinstigate.atlassian.net/wiki/spaces/RH/pages/9207882/Reference+sheet , But I am not able to update my object. patch call is not give me 200 ok status.

I am able to use patch, but I am not able to find out a particular object for the update.

Rh.one('db')
  .one('api')
  .patch(counter, {}, {})
  .then(function(response){

});

When I try some condition if-match in curly braces then I get this error:

412 (Precondition Failed) LIKE

Rh.one('db')
  .one('api')
  .patch(counter, {}, {"If-Match": index.name})
  .then(function(response){

});

I want to update particular object with patch.

Varun Sharma
  • 4,632
  • 13
  • 49
  • 103

1 Answers1

0

To update a document the URI needs to be /db/coll/<docid>

You are missing the document ID in the request URL.

Andrea Di Cesare
  • 1,125
  • 6
  • 11
  • Thanks for the answer. Now I am getting 200 ok status. But My object is not updating. I am following this syntax, Rh.one('rdb').one('collectionname').patch({ "If-Match": etag }, { 'counter': 15 }, {}).then( – Varun Sharma Jan 07 '18 at 08:08
  • In network I am hitting http://localhost:8080/_logic/ls/service/risk/rdb/collectionname?counter=15 And give me 200 ok with patch – Varun Sharma Jan 07 '18 at 08:12
  • I'm not sure about what you are trying to do. First the /_logic URI prefix means your are dealing with a custom handler; you have to check if it handles PATCH verb. Second the If-Match is an header used to avoid ghost writes, (see in documentation) but the custom handler should handle it... Can you please better explain what you want to achieve? – Andrea Di Cesare Jan 07 '18 at 12:41
  • Thanks for the answer – Varun Sharma Jan 08 '18 at 09:20