torbenrudgaard
torbenrudgaard

Reputation: 2551

MongoDB smarter use of $or when having many of the same comparisons

This works fine - I just wonder if there is a smarter way to do it?

db.getCollection("property")
     .find( { $or: [ { unique: "ATL-D406" }, 
                     { unique: "ATL-D407" }, 
                     { unique: "ATL-D411" }, 
                     { unique: "ATL-D412" } ] } )

Perhaps something like;

$or {unique: ["ATL-D406", "ATL-D407", "ATL-D411", "ATL-D412"]} ?

Upvotes: 1

Views: 28

Answers (1)

buræquete
buræquete

Reputation: 14688

You can use $in operator, which is detailed here

Usage is as below;

db.getCollection("property")
      .find( { unique: { $in: [ "ATL-D406", "ATL-D407", "ATL-D411", "ATL-D412" ] } } )

Upvotes: 2

Related Questions