Which is the proper MongoDB query operator for this task?

Hello all,

Need some advice here. I need the following flow:

findOne, get the _id then insert new document into “request” collection. Will monitor one of the field in the new document.

If there is no positive change on the field (which should be respond from the findOne _id owner), a new findOne will be perform but this time, I wanted to exclude the first _id from the mongoDB query.

For each non-positive respond, I wish to push the _id into an array to be use on the next findOne as excluded _id.

Which MongoDB query operator suitable for this task? It should support array to be use as exclude list.

Something like:

Players.findOne({
  status: "online",
  gender: "male",
  _id: excludeThis ["sample_id1", "sample_id2", "sample_id3"]
});

Please advice, thank you.

Is $nin the proper operator for this task?

1 Like

Players.findOne({
status: “online”,
gender: “male”,
_id: {$nin:{[“sampleID1”, “sampleID2”, “sampleID3”]}}
});

1 Like

Ok thanks so much. Will proceed with this operator.