B
B
Babich_S2017-03-14 03:48:24
MongoDB
Babich_S, 2017-03-14 03:48:24

How to get results from multiple collections with one query?

Need NOT an alternative to SQL Join. No matter how much I tried to find a solution, and as soon as I didn’t formulate queries to the search engine, I constantly find only questions / answers about how to make an alternative to the Join query, link records from two collections by some field.
In my case, there are several collections with documents similar in structure, with slight differences (types of materials in the CMS, with different sets of fields, and some common ones, like title, created, updated). It is necessary to display all these materials in a common table, with pagination and general sorting by date added or another field that is available in all collections. I don't need to bind the fields of entities to each other in any way, but I need an alternative to a simple find () but only simultaneously from several collections. It would be possible to get the data with several requests, but then there is a problem with pagination and sorting - I don’t know how this can be implemented on the application side without pulling all records from the database for this.
Is it even possible to implement such a request? Please help me find a solution, or at least tell me which way to dig. Maybe some kind of hybrid solution to the problem, with multiple database queries and application-side processing, but without having to fetch all the data? I understand that in the case of MongoDB, you can also simply add all the documents into one collection, no matter how they differ in structure, but for a number of reasons I would not want to do this.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question