Hi there.
I have a search function that currently returns an array of records from a collection that match a criteria.
Here is a simplified result:
[{"_id":"653d383456aa701344da1330","bookName":"Test Book","ownerId":"AijoAaT6VAQYJfnxwi7Krxl65C73"},
{"_id":"653bddf92ff8543b0c418220","bookName":"Test Programming","ownerId":"AijoAaT6VAQYkQExwi7Krxl65C73"},
{"_id":"6534069f1241c256efb3f91a","bookName":"Test","ownerId":"AijoAaT6VAQYkQExwi7Krxl65C73"}]
After getting this result, I now need to loop through each record in the returned result array, use the ownerId to look up another collection named “owners”, find the name associated with that “ownerId”, and then replace “ownerid” with the result of this lookup. As in, for each record in the result array, instead of a field like:
"ownerId":"AijoAaT6VAQYkQExwi7Krxl65C73"
I need:
"ownerName":"Jeff"
Pretty new to this stuff, so would appreciate any and all advice. Have read into $lookup but not entirely sure.