Wir haben folgende 2 Mongo Elemente mit internen Arrays „posts“
[codesyntax lang=“glsl“]
{
"_id" : ObjectId("56d34d6f4f6634a340b8da81"),
"good" : 478,
"bad" : 108,
"extId" : "/ASD",
"id" : NumberLong(746),
"posts" : [{
"order" : 0,
"time" : "18:53",
"text" : "Ich hab Block1",
"leftSide" : true
}, {
"order" : 1,
"time" : null,
"text" : "Ich suche Block 2",
"leftSide" : false
}]
}
/* 1 */
{
"_id" : ObjectId("56d34d9f4f6634a340b8ddc7"),
"good" : 836,
"bad" : 303,
"extId" : "/chat239782",
"id" : NumberLong(1482),
"posts" : [{
"order" : 0,
"time" : "23:21",
"text" : "wirklich ein Highlight.",
"leftSide" : true
}]
}
[/codesyntax]
Wenn wir jetzt innerhalb der Elemente suchen wollen brauchen wir etwas um in den Arrays zu suchen.
„$elemMatch “ übernimmt dieser Rolle:
find({ „posts“ : { „$elemMatch“ : { „text“ : /.*Highlight.*/ } } })