skip to Main Content

i have a controller function as:

User.updateOne(
    { _id: "6252d87e010b3f94adcf4e41" },
            {
                $pull: {
                    newCart: {
                        "post._id": "6249e216c1e3b6ae2d4aa273",
                    },
                },
            },
            {new:true}
        ).then((res) => console.log(res, user));

The response is like this:

{
  acknowledged: true,
  modifiedCount: 1,
  upsertedId: null,
  upsertedCount: 0,
  matchedCount: 1
}

It shows modifiedCount to 1 but never changes in my realtime database collection.

My collection looks like this:
Image of my db collection

2

Answers


  1. The query is correct maybe try adding exec

    User.updateOne(
      { _id: "6252d87e010b3f94adcf4e41" },
      {
        $pull: {
          newCart: {
            "post._id": "6249e216c1e3b6ae2d4aa273",
          },
        },
      },
      { new: true }
    )
      .exec()
      .then((res) => console.log(res, user));
    

    Hope this will solve the issue.

    Login or Signup to reply.
  2. your query is completely fine. disconnect your database and try to connect again. after restart maybe this will work

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search