Looking up field in another Collection and replacing it with lookup value

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.

We need more details.

How do you obtain the array of documents with the field ownerId?

You mentioned of function but it is not clear what driver you are using. It is not clear if it is an aggregation or a simple query. You could share the code to see how it could be modified to do the $lookup.