$lookup with conditional localField

That is why it is best to publish real documents from your collections. When I see

const obj = {
    _id: ObjectId('3432sdscscsc'),
    b: 'string'
};

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.

You will not be able to use the localField/foreingField version. You will need to use the version at https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/#join-conditions-and-subqueries-on-a-joined-collection.

Also see Conditional $lookup