I'm trying to pull an element in an array with e two level deep complexity
My document :
> db.users.find({ mail : '[email protected]'}).pretty()
{
"_class" : "bean.User",
"_id" : ObjectId("52f504bb2f9dd91186211537"),
"commandes" : [
{
"adresse" : "15 rue de la soif",
"codePostal" : "29200",
"idCommande" : 1,
"montantTotal" : 0,
"nom" : "TOTO",
"prenom" : "tata",
"ville" : "Brest",
"voyagesSouscrits" : [
{
"idVoyage" : "123",
"duree" : 1,
"nbPersonnes" : 0,
"villeDepart" : "Nantes",
"prixVoyage" : 999999
},
{
"idVoyage" : "addVoyageSouscrit",
"duree" : 1,
"nbPersonnes" : 0,
"villeDepart" : "Toulouse",
"prixVoyage" : 7777
}
]
},
{
"idCommande" : 1,
"dateCommande" : ISODate("2014-02-07T16:07:23.930Z"
),
"nom" : "TOTO",
"prenom" : "tata",
"adresse" : "15 rue de la soif",
"ville" : "Brest",
"codePostal" : "29200",
"montantTotal" : 0,
"voyagesSouscrits" : [
{
"idVoyage" : "123",
"duree" : 1,
"nbPersonnes" : 0,
"villeDepart" : "Toulouse",
"prixVoyage" : 666666
}
]
}
],
"mail" : "[email protected]",
"password" : "tata"
}
In a first step i want to pull the "voyagesSoucrits" elements with id "123".
According to this post :
MongoDB pull element from array two levels deep
I tried :
> db.users.update({ mail : '[email protected]', "commandes.voyagesSouscrits.idVoyage" : "123"},{$pull : {"commandes.$.voyagesSouscrits" : {"commandes.voyagesSouscrits.idVoyage" : "123"}}})
It didn't worked !
I did something wrong but i can't find it.... Any idea ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…