Can I get all collection's data in a single request?

I am working a project where I create database for every organization.I mean we have a core database for our important details and every organization has a database for their data.If we will have 100 organization we will have 100 database. We did this for our client requirments.So,Is there any solution to get all collection data of a database in a single query??

Hi @Moyen_Islam,

We did this for our client requirments.So,Is there any solution to get all collection data of a database in a single query??

I believe there isn’t a directly a single command available currently that would retrieve all documents from all collections in a single database.

One idea could be to possibly use listCollections and then pass the resulting collection names to a script which runs the query for the data you require.

Regards,
Jason

I think we’ve connected in the past Moyen, so pardon any repetition, but you will be able to do this shortly and easily using Atlas Data Federation.

Is use case to basically have something like:
Db1.CollEvents
Db2.CollEvents
Db3.CollEvents

And be able to query GlobalDB.CollEvents and have this represent data from each of the 3 CollEvents above?

2 Likes

Could you suggest any course or documentation about this. I have learn more about this.

Hey @Moyen_Islam , we just released this actually. You can read up on the documentation here:

To make it a bit easier though, this example shows how you can get collections named “user_feedback” across multiple different databases combined into one collection in a single database using data federation. One bonus is that this will also use our new provenance feature to include the source in a new field in your documents called “_provenance_data”. In this case that source is the source db, source collection, source cluster where the data is coming from.

{
  "databases": [

  "name": "GlobalVirtualDB",
    {
      "collections": [
        {
          "name": "user_feedback",
          "dataSources": [
            {
              "collection": "user_feedback",
              "databaseRegex": ".*",
              "provenanceFieldName": "_provenance_data",
              "storeName": "Storename"
            }
          ]
        }
      ],
      "views": []
    }
  ],
  "stores": [
    {
      "clusterName": "<CLUSTER_NAME>",
      "name": "StoreName",
      "provider": "atlas",
      "readPreference": {
        "mode": "secondary",
        "tagSets": []
      }
    }
  ]
}
2 Likes