1
productos: [
  {
    name: element 1
    number: 3167518236
    email: "example@gmail.com"
  }
  {
    name: element 2
    number: 3167518236
    email: "example@gmail.com"
  }
{
    name: element 3
    number: 3167518236
    email: "example@gmail.com"
  }
]

How can I for example remove the array two where name: element2 number: 3167518239 and email: example@gmail.com

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

db.list.update({},{"$unset":{productos:{name:"element 2"}}})
Community
  • 1
  • 1
krlosruiz
  • 113
  • 3
  • 11
  • possible duplicate of http://stackoverflow.com/questions/22065314/remove-a-subdocument-nested-in-an-array-in-mongodb and http://stackoverflow.com/questions/17823198/removing-a-subdocument-from-array-in-mongoddb – Saheed Hussain Jun 11 '14 at 01:30

1 Answers1

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.

Ray Toal
  • 86,166
  • 18
  • 182
  • 232