Optimized way of Querying in MongoDB using $in vs $or

前端 未结 4 1163
别那么骄傲
别那么骄傲 2020-12-03 15:09

Implementing an application that looks up a table for mail id presence from a list of around 10 email ids. Tried using $or and $in.

$in seems to give better performa

4条回答
  •  情书的邮戳
    2020-12-03 16:03

    $or operator is logical operator where you can define your own login but $in operator is Comparison operator where you can compare you can not put your on logic.

    Syntax of $in:

    { field: { $in: [, , ...  ] } }
    

    Example:

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

    Syntax of $or:

    { $or: [ {  }, {  }, ... , {  } ] }
    

    Example:

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

    Note: Account is your collection name

提交回复
热议问题