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

collection.find that doesn't match any elements in an array

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

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

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

使用 mongodb not-in $nin 运算符:

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