How to merge results from one collection in with another unrelated collection

I have two collections (Collection A and B) in one database. Collection A can be considered the main content and Collection B can be considered advertising which just needs to be mixed into the main feed every nth position. I want to make that single result set available through the GraphQL API which will receive search queries for the data (Collection A) and return the mixed result set (Collection A + B mixed in).

Can anyone advise where and how it is best to perform that merge?

I don’t want to $merge results into a new collection. That would just duplicate data and be something to keep in sync. I also need users to be able to search for pure content (Collection A only).

I also don’t want to $lookup. I’m not performing a join as there is nothing to join on. The two datasets are not related in any way. It’s just a case of placing adverts (Collection B) into a content stream (Collection A).

Would it be advisable to do this in a function for a custom resolver?

Any pointers appreciated.

1 Like

Just to be clear, I’m mostly looking for advice as to the best place and the best time to do this rather than the code to do it.

Is this best performed after conducting the search in Collection A and then manipulating the results by combining Collection B before returning it back to the user through the GraphQL API? Or is it better to do this in the client or elsewhere?