我试图避免不得不使用另一个循环清除ID在我的workerThatApplied数组中的工作人员。有没有办法在我的查询中完成此操作?
workersThatApplied = ['ehslj8373d', 'gkjhgjr737d'];
Workers.find({
'userId: // only select workers who's id isn't in the workersThatApplied array
'Trades': {$exists: true},
})
答案 0 :(得分:0)
使用mongodb非$nin运算符:
const workersThatApplied = ['ehslj8373d', 'gkjhgjr737d'];
Workers.find({
userId: { $nin: workersThatApplied },
Trades: { $exists: true },
});