Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

384
Views
How to delete object inside an array in mongodb collection?

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

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report

0

your query is completely fine. disconnect your database and try to connect again. after restart maybe this will work

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!