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

436
Views
Delete single array object in mongodb uing $unset

https://mongoplayground.net/p/Yv6vkGyrUS-

https://mongoplayground.net/p/vm314GoexjE

[
 {
   "_id": ObjectId("4b253b067525f35f94b60a31"),
  "age": 30,
  "favorite book": [
  "Cat's Cradle",
  "Foundation Trilogy",
  "Ender's Game"
   ],
"location": "Wisconsin",
"name": "joe",
"sex": "male"
}
]

output delete any element with based on condition

"favorite book": [
  "Cat's Cradle",
  "Foundation Trilogy"
   ]
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use $pull operator

db.collection.update({
    { _id : id },
    { $pull: { "favorite book": "Ender's Game" } }
});

If you want to remove two or more elements from the array "list", you can do that with $pull operator, as well:

db.collection.update({
    { _id : id },
    { $pull: { "favorite book" : { $in : [ "Foundation Trilogy", "Ender's Game"] } } }
});

Please check How do I remove a string from an array in a mongodb document?

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!