1
productos: [
  {
    name: element 1
    number: 3167518236
    email: "[email protected]"
  }
  {
    name: element 2
    number: 3167518236
    email: "[email protected]"
  }
{
    name: element 3
    number: 3167518236
    email: "[email protected]"
  }
]

How can I for example remove the array two where name: element2 number: 3167518239 and email: [email protected]

I'm using this but it doesn't work!

db.list.update({},{"$unset":{productos:{name:"element 2"}}})
1

1 Answer 1

3

Removing an element from an array in mongodb is done using the $pull operator.

For your particular case, you can use {name:"element 2"} as the query inside the pull specification.

Sign up to request clarification or add additional context in comments.

1 Comment

db.usuarios.update({},{"$pull":{productos:{nombre:"element 2"}}}) still not working!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.