Ist es möglich, ein OR in $ match zu erstellen?MongoDB-Aggregationsframework-Übereinstimmung ODER
Ich meine etwas wie folgt aus:
db.articles.aggregate(
{ $or: [ $match : { author : "dave" }, $match : { author : "john" }] }
);
Ist es möglich, ein OR in $ match zu erstellen?MongoDB-Aggregationsframework-Übereinstimmung ODER
Ich meine etwas wie folgt aus:
db.articles.aggregate(
{ $or: [ $match : { author : "dave" }, $match : { author : "john" }] }
);
$match: { $or: [{ author: 'dave' }, { author: 'john' }] }
Wie so, da der $match
Betreiber genau das, was bringt Sie normalerweise in die find()
Funktion setzen würde
Besonders auf Ihre Frage über das heißt
gefragtdb.articles.aggregate(
{ $or: [ $match : { author : "dave" }, $match : { author : "john" }] }
);
Ich würde t empfehlen o gehen mit $in
Operator für die gleiche dh Abfrage wie folgt:
$match : { 'author' : { $in: ['dave','john'] }
Laut Mongo Docs, diese "effektivste" Art, es für Gleichheitsvergleiche wie Ihr Beispiel zu tun. Siehe http://docs.mongodb.org/manual/reference/operator/query/or/#_S_or%22 –
Das $ in ist der Weg zu gehen – blueskin
Ich glaube, $ oder ist kein Aggregation-Operator. –
Hallo, kann dieser Link helfen http://www.codefari.com/2015/11/match-aggregation-in-mongodb-with. html – Singh