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

267
Views
How do I pull an ObjectId from array in Mongoose document?

I want to pull (remove) an ObjectId from an array in a Mongoose document, but it isn't removed. The code is like this

UserModel.updateOne({ _id: author._id }, {
    $pull:
        { snippets: { _id: ObjectId(snippet._id) } }
  })

The author._id is the ID of the particular user of the UserModel. snippets is an array of ObjectId's referring to another schema. snippet is the document whose ObjectId I want to remove from the array.

I think I have made it clear what I want, but the ObjectId is not removed from the array, which I can see in the database.

about 4 years ago · Juan Pablo Isaza
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!