与数组中的任何元素都不匹配的collection.find

时间:2018-07-15 21:32:16

标签: mongodb meteor

我试图避免不得不使用另一个循环清除ID在我的workerThatApplied数组中的工作人员。有没有办法在我的查询中完成此操作?

  workersThatApplied = ['ehslj8373d', 'gkjhgjr737d'];

  Workers.find({
    'userId: // only select workers who's id isn't in the workersThatApplied array 
    'Trades': {$exists: true},
  })

1 个答案:

答案 0 :(得分:0)

使用mongodb非$nin运算符:

const workersThatApplied = ['ehslj8373d', 'gkjhgjr737d'];
Workers.find({
  userId: { $nin: workersThatApplied },
  Trades: { $exists: true },
});