How to use Atlas search on multiple collections - mongodb

I have two collections, that are store on Atlas.
I want to be able to search for a text, using the regex operator of Mongo Atlas Search on these two collections, but with only one aggregation.
These two collections have nothing in common, so I can't do a $lookup on it.
I need to do this search in one aggregation because the result of this aggregation must be paginated with $limit and $skip in the aggregation.
How to perform that ?

You can use Atlas Data Lake on top of these two collections to federate queries across both. To do this you would create a Data Lake, create a virtual collection in your Data Lake, and then have both of these collections listed as "datasources" for that virtual collection.
The Data Lake infrastructure will push down queries to the underlying cluster and union the results before returning them to the client application.
In this example there are multiple types of data sources, but you can just list multiple cluster collections.
https://docs.mongodb.com/datalake/reference/format/data-lake-configuration/#example-configuration-for-running-federated-queries

Related

Is it possible to create sub Collection like Firebase FireStore in MongoDB atlas?

Can we create sub Collection inside a mongoDB document as we can create in firebase firestore?
MongoDB's logical architecture is:
Cluster
- Database
-- Collection
--- Document
You can have multiple databases, each with multiple collections, each with multiple documents, each with what ever you want to put in your documents.
Documents can have complex fields like objects/dictionaries and lists/arrays.
You can index on inner fields, not only on the top level ones.

One Query to Join Multiple Mongo Databases for Dashboard

I have several separate Mongodb databases with identical collection structure. They have to be separate databases for legal reasons.
I would like to be able to create a query that pulls data across all separate databases, combine the data into a single dataset so I get one view across all of my separate databased.
Assume that my databases are named db1, db2, db3. Assume that the collections inside each are the same structure. col1.name, col1.address, col1.zip
What kind of query will pull names from each collection from all databases?

How to query documents from an entire MongoDB database containing multiple collections at once (Pymongo)

I have a DB containing thousands of collections, each collection containing documents.
How would I query all these documents from all the collections at once?
I have considered using the $lookup aggregation method but from my knowledge, it only combines an additional collection at once, whereas I have thousands of collections that I want to combine and query altogether.
Is there a way to achieve this?
MongoDB operations work on a single collection at a time. As you point out, $lookup can perform a cross-collection lookup, but it won't help you with a large number collections.
Re-design your data model.

Aggregation across multiple databases in MongoDB or solution to sync collections across databases

We have a requirement in our project to write aggregation queries across multiple mongodb databases. I see that it is not possible with Mongo to query another database in an aggregate query. What would my options be in this case?
We would not mind to create the same collections manually across multiple databases as long as these derived collections sync automatically when the primary collection is updated. Does Mongo have any such solutions to keep collections across databases in sync?
"Almost." You can use the Change Stream feature to listen for changes on the source database but you must write a piece of code to insert/update the material into the target database.

SQL view in mongodb

I am currently evaluating mongodb for a project I have started but I can't find any information on what the equivalent of an SQL view in mongodb would be. What I need, that an SQL view provides, is to lump together data from different tables (collections) into a single collection.
I want nothing more than to clump some documents together and label them as a single document. Here's an example:
I have the following documents:
cc_address
us_address
billing_address
shipping_address
But in my application, I'd like to see all of my addresses and be able to manage them in a single document.
In other cases, I may just want a couple of fields from collections:
I have the following documents:
fb_contact
twitter_contact
google_contact
reddit_contact
each of these documents have fields that align, like firstname lastname and email, but they also have fields that don't align. I'd like to be able to compile them into a single document that only contains the fields that align.
This can be accomplished by Views in SQL correct? Can I accomplish this kind of functionality in MongoDb?
The question is quite old already. However, since mongodb v3.2 you can use $lookup in order to join data of different collections together as long as the collections are unsharded.
Since mongodb v3.4 you can also create read-only views.
There are no "joins" in MongoDB. As said by JonnyHK, you can either enormalize your data or you use embedded documents or you perform multiple queries
However, you could also use Map-Reduce.
or if you're prepared to use the development branch, you could test the new aggregation framework though maybe it's too much? This new framework will be in the soon-to-be-released 2.2, which is production-ready unlike 2.1.x.
Here's the SQL-Mongo chart also, which may be of some help in your learning.
Update: Based on your re-edit, you don't need Map-Reduce or the Aggregation Framework because you're just querying.
You're essentially doing joins, querying multiple documents and merging the results. The place to do this is within your application on the client-side.
MongoDB queries never span more than a single collection as there is no support for joins. So if you have related data you need available in the results of a query you must either add that related data to the collection you're querying (i.e. denormalize your data), or make a separate query for it from another collection.
I am currently evaluating mongodb for a project I have started but I
can't find any information on what the equivalent of an SQL view in
mongodb would be
In addition to this answer, mongodb now has on-demand materialized views. In a nutshell, this feature allows you to use aggregate and $merge (in 4.2) to create/update a quick view collection that you can query from faster. The strategy is used to update the quick view collection whenever the main collection has a record change. This has the side effect unlike SQL of increasing your data storage size. But the benefits can be huge depending on your querying needs.