ich folgende mongodb Sammlung Beiträge mit Dokument wie folgt benannt habe:wie ein Element aus einem MongoDB Array Dokumenten entfernen
{
"_id" : "111",
"comments" : [
{
"replyPost" : "aaaa",
"username" : "John Doe"
},
{
"replyPost" : "bbbb",
"username" : "Jane Smith"
},
{
"replyPost" : "cccc",
"username" : "Jane Smith"
},
{
"replyPost" : "dddd",
"username" : "Jane Smith"
}
]
}
Ich versuche, ein Array-Element mit dem replyPost zu entfernen: „cccc“, so dem Ergebnis wäre:
{
"_id" : "111",
"comments" : [
{
"replyPost" : "aaaa",
"username" : "John Doe"
},
{
"replyPost" : "bbbb",
"username" : "Jane Smith"
},
{
"replyPost" : "dddd",
"username" : "Jane Smith"
}
]
}
ich habe versucht, .update Methode mit $ beziehen ziehen Dokument MongoDB https://docs.mongodb.com/manual/reference/operator/update/pull/
Posts.update(
{_id: this._id},
{ $pull: { comments: { replyPost:"cccc"} } }
);
die scheinen nicht zu funktionieren. Kann jemand das Problem sehen?
Ich habe überprüft und Abfrage funktioniert in mongoshell – styopdev