Hi,
I wanted to search in a nested mongo doc for values with a specific name.
The structures of the a little complex but the names of the values are always the same. Here is what one document is looks like:
{
"nr" : "00000209",
"tx" : "text",
"list" : [
{
"featurename" : "text",
"featuretext" : "text"
},
{
"featurename" : "text",
"featuretext" : "text",
"features" : [
{
"some" : "text",
"featurekeys" : [
{
"featurekey" : "text"
},
{
"featurekey" : "text"
},
{
"featurekey" : "text"
},
{
"featurekey" : "text"
},
{
"featurekeys" : ""
}
]
}
]
},
{
"featurename" : "text",
"featuretext" : "text",
"features" : [
{
"some" : "text",
"featurekeys" : [
{
"featurekey" : "text"
},
{
"featurekey" : "text"
},
{
"featurekey" : "text"
},
{
"featurekey" : "text"
},
{
"featurekeys" : "text"
}
]
},
{
"some" : "text",
"featurekeys" : [
{
"featurekey" : "text"
}
]
}
]
}
]
}
Normally I’ve a list of values [‘taxtA’, ‘textB’, ‘textC’] and i have to look through all the featurekey fields if one or more values from my list are there.
My attempt looked like this, but gave me strange results:
{list: {$elemMatch: { features.featurekeys.featurekey:{ $all:[ RegExp('.*TextA.*'), RegExp('.*TextB.*'), RegExp('.*TextC.*')]}}}}
Can anyone tell me what I am doing wrong?