it’s pretty easy and straightforward to do CREATE , RETRIEVE and DELETE of CRUD
but the UPDATE is what i am really stuck at with mongo using Dreamfactory live api
how can i achieve the following
get the record without using id and if it exists update (or append ) the data
if not exists then create it
There are a couple of options for implementing the “if it doesn’t exist then create the record, otherwise update the record” logic.
The client app can make a GET request and if the response is null then make a POST request to create a new record, else make a PUT (or PATCH) request on the returned record.
Alternatively, you could implement this same logic using a server-side script in DreamFactory (i.e., make a single GET request and let the server handle the POST vs PUT/PATCH logic instead of generating a second API call from the client).
thanks ben for your prompt reply
the logic that you have mentioned worked perfectly
if in future you can put an example then it would definitely help other users
what i found is that i would like to share with you for mongodb upsert
getRecordsByFilter() just specify the
filter to be the criteria for e.g
{“0”: “bobthebuilder@norbiton@1”} all fields 0 whose content is bobthebuilder@norbiton@1
if it exists it will return the _id , else null
and for the update
updateRecord() - Update (patch) one record by identifier.
this works exactly in the same manner as i have wanted
just specify table name , id that you get previously
and in the body the fields that you need to change (if it won’t exist it will create it for you)
This may get you going in the right direction or maybe not… waiting to hear back from engineering until then, see how this works. You may need to add another layer for the zip. Most likely you will need to tweak this code a bit - let me know.
One last thing, the order in which these filter params are listed need to be in the hierarchy that matches your DB…
I have also great in using Mongodb
and I like all functionality. Here I would like to mention a link that Will
help you to do insert , Update and delete in a single article. All the things
is discussed properly. Feel free to visit:Click