让我们假设我的收藏包含以下元素:
const Item = mongoose.Schema({
type: { type: String },
group: { type: Number }
});
[
{ type: "A", group: 1 },
{ type: "B", group: 1 },
{ type: "C", group: 1 },
{ type: "A", group: 2 },
{ type: "B", group: 2 },
{ type: "C", group: 2 },
]
现在我想执行一个 find
操作但想排除以下项目:
const items = [
{ type: "A", group: 1 },
{ type: "B", group: 1 },
];
const result = await Model.find({ /* ??? */ });
查询必须如何查看才能获得以下响应?
const result = [
{ type: "C", group: 1 },
{ type: "A", group: 2 },
{ type: "B", group: 2 },
{ type: "C", group: 2 },
];
答案 0 :(得分:1)
尝试 $nor 运算符,对一个或多个查询表达式的数组执行逻辑 NOR 运算,并选择数组中所有查询表达式失败的文档。
const items = [
{ type: "A", group: 1 },
{ type: "B", group: 1 },
];
const result = await Model.find({ $nor: items });