I have large collection of documents in MongoDB
with the following structure as an example:
{ "key" : "a" ,"data" : "value1" , "lastname" : "Doe" }<br>
{ "key" : "ab" , "data" : "value1" , "lastname" : "Doe" }<br>
{ "key" : "abc" , "data" : "value1" , "lastname" : "Doe" } <<< <br>
{ "key" : "d" , "data" : "value2" , "lastname" : "Doe" }<br>
{ "key" : "df" , "data" : "value2" , "lastname" : "Doe" }<br>
{ "key" : "dfg" , "data" : "value2" , "lastname" : "Doe" } <<< <br>
I need to get data from those two lines marked by <<<
based on terms that key
on those lines
already includes key values from other documents for the same lastname
i.e. "abc" has "ab" and "ab" has "a", result I needed should look like this:
{ "lastname" : "Doe" , "value1" : "abc" , "value2" : "dfg" }
I can pull data in 2 passes by creating 2 separate queries , but I want to see if this can be done in just one.