question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Patch is deleting subdocument data

See original GitHub issue

My 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

7reactions
dafflcommented, Nov 5, 2016

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.

6reactions
imnscommented, Nov 2, 2016

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

"$set": { 
        "social.twitter.username": "@test"
    } 
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found