PUT/PATCH don't support mongoose update operations
See original GitHub issueThis should work:
curl -XPUT /api/v1/User -d {"$addToSet": {"friends": "BoB"}}
but because we use document.set instead of document.update we loose the ability to use any of the mongodb update operators
currently the way that request is handled it results in doing the following operation:
doc.save({'$addToSet.friends': 'BoB'})
instead of the desired:
doc.update({'$addToSet': {'friends': 'BoB}})
What do you think of this proposed solution? not tested yet, but seems to work on my use-cases
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
RESTful API, patch, mongoose update command doesn't ...
Patch method with mongoose update doesn't work instead just clears field which I try to update. I have tried update , updateOne ,...
Read more >API with NestJS #49. Updating with PUT and PATCH with ...
Implementing the PUT method with MongoDB and Mongoose. There are quite a few ways of implementing a proper PUT method with MongoDB and...
Read more >What's the Difference between PUT vs PATCH? - RapidAPI
PUT/PATCH – Update; DELETE – Delete. From this mapping, it is not surprising that most people think that PUT and PATCH are allies...
Read more >Developing RESTful APIs with Hapi - Auth0
API should respond to common HTTP verbs, GET , POST , PUT , PATCH , DELETE ... We have defined the dog attributes...
Read more >PUT/PATCH not going through when using postman + express
I'm trying to update a user's shipping information. I have default data in mongodb that ... .exports = mongoose.model("Shipping", ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s a good point about deep endpoints.
For me, the key feature in opening up all of the MongoDB update operators is actually field deletion, because it’s not currently possible to remove a field from a document.
To perform PUT/PATCH ops, we’re using
If we update PUT to completely replace the document, we would at least get field deletion via PUT, but we still won’t have deletion via PATCH (which will still need to use
$set
)If you decide to change this, please give consideration to the different semantics of PUT and PATCH. PUT is meant to replace a whole document. PATCH on the other hand is meant for just this use case.
There is a very good reason to separate PUT from PATCH. PUT is idempotent, which means that a client can assume that applying a PUT operation twice will give the same result as applying it once. So, while $addToSet happens to be idempotent, operations like $push are not.