I have a json where i am trying to filter my pipeline with multiple fields where some fields can have null value as well. sender.client and receiver.client may not always values
Below is the part of sample 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"
}
}
I am aiming to filter with condition if (sender.client = spec1 or receiver.client =spec1) then display all fields, i.e if the name of the client matches then i have to display other required fields. I have been trying with $project and $match but match is not working with $cond , so i have taken alternate route with $eq but it's not helping me filter out my requirement. Below is my code:
{
"$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
}
}
}
}
I want to use $match inpace of $eq. How do i accomplish this?