我有一个json
. sender.client和receiver.client不能总是值
下面是示例json的一部分:
{"sender" : {
"id" : "5d95",
"name" : "Name1",
"phone" : "123456",
"client" : "spec1"
},
"receiver" : {
"id" : "5d95683",
"name" : "name2",
"phone" : "342235",
"client" : "spec1"
}
}
{"sender" : {
"id" : "52fes",
"name" : "Name2",
"phone" : "3334321",
"client" : "spec2"
},
"receiver" : {
"id" : "5efse",
"name" : "name3",
"phone" : "7353344",
"client" : "spec1"
}
}
我的目标是过滤条件
(sender.client=spec1或receiver.client=spec1)
然后显示所有字段,即如果客户端名称匹配,则必须显示其他必需字段。我一直在尝试$project和$match,但是match不使用$cond,所以我选择了$eq的替代路径,但这并不能帮助我过滤掉我的需求。以下是我的代码:
{
"$project" : {
"sendername" : {
"$cond" : {
"if" : {
"$eq" : [
"$sender.client",
"spec1"
]
},
"then" : "$sender.name",
"else" : 0.0
}
},
"sendername1" : {
"$cond" : {
"if" : {
"$eq" : [
"$receiver.client",
"spec1"
]
},
"then" : "$receiver.name",
"else" : 0.0
}
}
}
}
我想在$eq的空间中使用$match。我该如何完成?