Optimized query method in MongoDB using $ in vs $ or

An application that looks for a table for a mail identifier from a list of 10 email identifiers. Tried to use $ or and $ in.

$ seems to give better performance, but not significant. Is one more optimized?

+5
source share
3 answers

MongoDB docs have the answer :

"When using $ or with <expressions>, which are equality checks for the value of the same field, select the $ in operator over $ or the operator."

+15
source

"" $ " , " $in ", , ".

, "$ in" .

: MongoDB:

+1

$or - , , $in , , .

$in:

{ field: { $in: [<value1>, <value2>, ... <valueN> ] } }

:

db.account.find( { qty: { $in: [ 5, 15 ] } } )

$or:

{ $or: [ { <expression1> }, { <expression2> }, ... , { <expressionN> } ] }

:

db.account.find( { $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] } )

. -

0

All Articles