Patch is deleting subdocument data
See original GitHub issueMy API uses feathers-mongoose
for the db and when I send JSON (via postman) to patch
my model I’m losing subdocument (embedded?) data. For example, if I have a model like this
social: {
facebook: {
url: String,
likes: Number
},
twitter: {
username: String,
followers: Number
}
}
and I send a patch request with
{
"social": {
"twitter": {
"username": "@the_username"
}
}
}
it deletes social.facebook
Expected behavior
It shouldn’t delete the sibling subdocuments. In this example social.facebook
.
System configuration
Module versions (especially the part that’s not working): feathers-mongoose@3.5.3
NodeJS version: v6.5.0
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Remove Subdocument items with $pull - Stack Overflow
I'm trying to remove items from subdocuments using ExpressJS and Mongoose but it is only removing the first items, not the sub items....
Read more >MongoDB removing subdocument issue - Working with Data
I'm trying to remove specific sub document by it's _id. ... const removedPost = await eventArrayModel.update({resource: req.params.
Read more >6 Writing a REST API: Exposing the MongoDB database to the ...
6.6 DELETE method: Deleting data from MongoDB. The DELETE method is, unsurprisingly, all about deleting existing documents or subdocuments in the database. In ......
Read more >Adding, Updating, and Removing Subdocuments with ...
If I go to my database on MongoDB and navigate to the user I just edited, I'll be able to find the post...
Read more >Partial document update in Azure Cosmos DB - Microsoft Learn
Set operation is similar to Add except in the case of Array data type - if the target path is a valid array...
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
I think this has been figured out right? I think in general Feathers should leave the deep-merge behaviour up to the ORM since some (like all SQL ORMs) don’t even support nested objects at all.
I agree about using
$set
. This issue (https://github.com/feathersjs/feathers/issues/323) mentions that$set
is being used, but I don’t see that anywhere.@corymsmith I am not using feathers client. I’m sending a
patch
request directly to the API.Update
I just tried sending
{ $set: { "social.twitter": {username: '@the_username'} } }
with postman and it worked.This seems counterintuitive since a patch request by nature needs to use
$set
.Update2
$set
seems to want dot notation. This works