Linua_N_A
(Linua N/A)
March 21, 2023, 12:59pm
#1
Hey,
If i have an object like this one below, how could i set “Number” field in $project aggregation with Integer’s value if the Key.Name = “someName”?
{
"Categories": [
"Keys": [
{
"Name": "someName",
"Values": [
{
"Integer": 0
}
]
}
]
]
}
Hi @Linua_N_A - Welcome to the community.
Have you taken a look at the $cond
operator to see if it can help achieve what you’re after?
It would make it easier to assist as well if you could provide the following:
Whether or not the Keys
array will have multiple objects within
if "Key.Name"
exists multiple times, what is the expected output for "Number"
?
More sample documents and the expected output(s)
MongoDB version in use
Regards,
Jason