Please provide sample documents of both the source and looked up collections that represents the 2 situations.
But, an aggregation pipeline is simply an array of stages. Nothing stops you from using normal control flow statement of the programming language you use.
My problem is that I wanted to allow the user to upload data, for which some references were not passed along. Like: an invoice with a supplier, but without providing information from this supplier apart from the mere string of the name.
But now I thing I should just create an id for this supplier and simply not allow in the app entities without id.
I don’t know if that’s the solution. (I do thing so, although I also thought the other way was the solution). But I noticed that managing the inherent complexity of working with both id and string is just huge and not worth it.
Regarding your solution, I think I didn’t explained it well, but the obj.b, in my case, is not present in my app memory. obj is the mongo collection I’m looking it up. The “YourCollectionName”. The ideawas to provide a localField depending on one field in the retrieved object.
I see a constant object defined in JS code. Not a document in a collection. For this my solution is inadequate unless you want to pay the performance penalty of 2 database access.
Very true Steevej,
I over supposed. I looked those links you send and I’m wondering if that could be the solution for another issue I have.
Could you check this?
I think It can’t because that solution has to do with $lookup and I would need to perform with a bulk operation.