这是我所拥有的示例订购文件
//Order
{
other fields,
expertise = [
{ industry: "I1", service: "S1", competence: "C1", qualified: true },
{ industry: "I1", service: "S1", competence: "C2" }
]
}
这是用户文档的示例
//用户1
{
other fields,
expertise = [
{ industry: "I1", service: "S1", competence: "C1", qualified: true },
{ industry: "I1", service: "S1", competence: "C2" }
]
}
//User 2
{
other fields,
expertise = [
{ industry: "I1", service: "S1", competence: "C1", qualified: false },
{ industry: "I1", service: "S1", competence: "C2" }
]
}
qualified属性是布尔值和可选属性。
要求是获得给定订单的匹配用户(使用专业知识)。
订单中的所有专业知识应包括用户对象。 但是,
如果qualified
中的true
是expertise
,则需要返回Users
,而qualified
是true
如果qualified
中的false
是expertise
,则需要返回Users
,qualified
和true
都是false
以下查询成功,否定1。
db.getCollection('users').find({
expertise: {
$all: [
{ industry: "I1", service: "S1", competence: "C1", qualified: true },
{ industry: "I1", service: "S1", competence: "C2" }
]
}
});
但是要获得成功2,我需要查询以下内容。
db.getCollection('users').find({
expertise: {
$all: [
{ industry: "I1", service: "S1", competence: "C1", qualified: {$or: [true, false]} },
{ industry: "I1", service: "S1", competence: "C2" }
]
}
});
这不起作用。如何将其修改为成功No2。任何帮助将不胜感激。