I am facing a problem to remove duplicates after applying union with lookup. I have 2 collections. I need data in a way that if suppose record exist in primary collection and does not exist in secondary(lookup) collection it should return record from primary collection with secondary collection data as null. If record does not exist in primary collection it should return data from secondary collection as fields from primary collections as null and if record exists in both the collection it should return combined data like inner join. Now for me its returning separate data as from primary collection point of view, data as from secondary collection point of view, but i want combined data. Note - There are not unique fields on which we can have $group.
Paste examples of all the documents as well as the query you currently have, preferably in something like mongo playground so it’s easier for someone to look at. That way we don’t need to create data to look into your issue and can work with something similar to what you are working with.
If pasting document(s) into a post use the formatting tools to make then easier to work with.