Atlas Data Federation supports Atlas clusters as federated database instance stores. You must define mappings in your federated database instance to your Atlas cluster to run queries against your data.
Important
Information in your storage configuration is visible internally at MongoDB and stored as operational data to monitor and improve the performance of Atlas Data Federation. So, we recommend that you do not use PII in your configurations.
Example Configuration for Atlas Data Store
Example
Consider a M10 or higher Atlas cluster named
myDataCenter containing data in the metrics.hardware
collection. The metrics.hardware collection contains JSON
documents with metrics derived from the hardware in a datacenter.
The following configuration:
Specifies the Atlas cluster named
myDataCenterin the specified project as a federated database instance store.Maps documents from the
metrics.hardwarecollection in the Atlas cluster to thedataCenter.inventorycollection in the storage configuration.
{ "stores" : [ { "name" : "atlasClusterStore", "provider" : "atlas", "clusterName" : "myDataCenter", "projectId" : "5e2211c17a3e5a48f5497de3" } ], "databases" : [ { "name" : "dataCenter", "collections" : [ { "name" : "inventory", "dataSources" : [ { "storeName" : "atlasClusterStore", "database" : "metrics", "collection" : "hardware" } ] } ] } ] }
Atlas Data Federation maps all the documents in the metrics.hardware
collection to the dataCenter.inventory collection in the storage
configuration.
Users connected to the federated database instance can use the MongoDB Query Language
and supported aggregations to analyze data in the Atlas cluster
through the dataCenter.inventory collection. When you run
queries, the query first goes to Atlas Data Federation. Therefore, if you run
aggregation queries that are supported by your Atlas cluster but
not by Atlas Data Federation, the queries will fail. To learn more about supported
and unsupported commands in Data Federation, see Supported MongoDB Commands.
Configuration Format
The federated database instance configuration has the following format:
1 { 2 "stores" : [ 3 { 4 "name" : "<string>", 5 "provider": "<string>", 6 "clusterName": "<string>", 7 "projectId": "<string>", 8 "readPreference": { 9 "mode": "<string>", 10 "tagSets": [ 11 [{"name": "<string>", "value": "<string>"},...], 12 ... 13 ], 14 "maxStalenessSeconds": <int> 15 } 16 } 17 ], 18 "databases" : [ 19 { 20 "name" : "<string>", 21 "collections" : [ 22 { 23 "name" : "<string>", 24 "dataSources" : [ 25 { 26 "storeName" : "<string>", 27 "database" : "<string>", 28 "databaseRegex": "<string>", 29 "collection" : "<string>", 30 "collectionRegex" : "<string>", 31 "provenanceFieldName": "<string>" 32 } 33 ] 34 } 35 ], 36 "views" : [ 37 { 38 "name" : "<string>", 39 "source" : "<string>", 40 "pipeline" : "<string>" 41 } 42 ] 43 } 44 ] 45 }
stores- The
storesobject defines each data store associated with the federated database instance. The federated database instance store captures files in documents in Atlas cluster. federated database instance can only access data stores defined in thestoresobject. databases- The
databasesobject defines the mapping between each federated database instance store defined instoresand MongoDB collections in the databases.
stores
1 "stores" : [ 2 { 3 "name" : "<string>", 4 "provider" : "<string>", 5 "clusterName" : "<string>", 6 "projectId": "<string>" 7 "readPreference": { 8 "mode": "<string>", 9 "tagSets": [ 10 [{"name": "<string>", "value": "<string>"},...], 11 ... 12 ], 13 "maxStalenessSeconds": <int> 14 }, 15 "readConcern": { 16 "level": "<string>" 17 } 18 } 19 ]
storesArray of objects where each object represents a data store to associate with the federated database instance. The federated database instance store captures files in an S3 bucket, documents in Atlas cluster, or files stored at publicly accessible URLs. Atlas Data Federation can only access data stores defined in the
storesobject.
stores.[n].nameName of the federated database instance store. The
databases.[n].collections.[n].dataSources.[n].storeNamefield references this value as part of mapping configuration.
stores.[n].providerDefines where the data is stored. Value must be
atlasfor a collection in an Atlas cluster.
stores.[n].clusterNameName of the Atlas cluster on which the store is based. The cluster must exist in the same project as your federated database instance. The
sourcefield on the data partition is the name of the Atlas cluster.
stores.[n].projectIdUnique identifier of the project that contains the Atlas cluster on which the store is based.
stores.[n].readPreferenceOptional. Cluster read preference, which describes how to route read requests to the cluster.
Example
The following
readPreferencesetting specifiessecondarymode andANALYTICSnodeType.{ ... "stores": [ { "provider": "atlas", "clusterName": <CLUSTER_NAME>, "name": <STORE_NAME>, "projectId": <PROJECT_ID>, "readPreference": { "mode": "secondary", "tagSets": [ [ { "name": "nodeType", "value": "ANALYTICS" } ], ... ] } } ] }
stores.[n].readPreference.modeOptional. Read preference mode that specifies which replica set member to route the read requests to. Value can be one of the following:
primary- to route all read requests to the replica set primaryprimaryPreferred- to route all read requests the replica set primary and to secondary members only ifprimaryis unavailablesecondary- to route all read requests to the secondary members of the replica setsecondaryPreferred- to route all read requests to the secondary members of the replica set and the primary on sharded clusters only ifsecondarymembers are unavailablenearest- to route all read requests to random eligible replica set member, irrespective of whether that member is a primary or secondary
If omitted, defaults to
local.
stores.[n].readPreference.tagSetsOptional. Arrays of tag sets or tag specification documents that contain name and value pairs for the replica set member. If specified, Atlas Data Federation routes read requests to replica set member or members that are associated with the specified tags. To learn more, Read Preference Tag Sets.
Note
Atlas Data Federation doesn't support
tagSetsfor sharded clusters.
stores.[n].readPreference.maxStalenessSecondsOptional. Maximum replication lag, or "staleness", for reads from secondaries. To learn more about
maxStalenessSeconds, see Read Preference maxStalenessSeconds.
stores.[n].readConcernOptional. Consistency and isolation properties of the data read from an Atlas cluster. To learn more, see Read Concern. The value for the level of consistency and availability can be one of the following:
local- to return data from an instance with no guarantee that the data has been written to a majority of the replica set members. To learn more, see Read Concern "local".available- to return data from an instance with no guarantee that the data has been written to a majority of the replica set members. This can return orphaned documents when reading from a sharded collection. To learn more, see Read Concern "available".majority- to return data that has been acknowledged by a majority of the nodes on the Atlas cluster. To learn more, see Read Concern "majority".linearizable- to return data that reflects all successful majority-acknowledged writes that completed prior to the start of the read operation. To learn more, see Read Concern "linearizable".snapshot- to return majority-committed data as it appears across shards from a specific single point in time in the recent past. To learn more, see Read Concern "snapshot".
databases
1 "databases" : [ 2 { 3 "name" : "<string>", 4 "collections" : [ 5 { 6 "name" : "<string>", 7 "dataSources" : [ 8 { 9 "storeName" : "<string>", 10 "database" : "<string>", 11 "databaseRegex": "<string>", 12 "collection" : "<string>", 13 "collectionRegex" : "<string>", 14 "provenanceFieldName": "<string>" 15 } 16 ] 17 } 18 ] 19 } 20 ]
databasesArray of objects where each object represents a database, its collections, and, optionally, any views on the collections. Each database can have multiple
collectionsandviewsobjects.
databases.[n].nameName of the database to which Atlas Data Federation maps the data contained in the data store. You can generate databases dynamically by specifying
*for the database name. Dynamically generated databases:Can exist alongside explicitly defined databases. However, Atlas Data Federation won't dynamically generate databases with names that conflict with explicitly defined databases in the storage configuration.
Can only be from a single Atlas cluster. Atlas Data Federation won't dynamically generate databases from multiple Atlas clusters or other data stores.
databases.[n].collectionsArray of objects where each object represents a collection and data sources that map to a
storesfederated database instance store. For dynamically generated databases, you can define only one wildcard (*) collection object in the storage configuration.
databases.[n].collections.[n].nameName of the collection to which Atlas Data Federation maps the data contained in each
databases.[n].collections.[n].dataSources.[n].storeName. Each object in the array represents the mapping between the collection and an object in thestoresarray.You can generate collection names dynamically by specifying
*for the collection name and omitting thecollectionfield. To dynamically generate wildcard (*) collections for dynamically generated wilcard (*) databases, specify thedatabases.[n].collections.[n].dataSources.[n].storeNameoption and omit thedatabases.[n].collections.[n].dataSources.[n].databaseoption. Note that for dynamically generated databases, you can define only one wildcard (*) collection object in the storage configuration.For wildcard (
*) collections, you can also define regex patterns usingdatabases.[n].collections.[n].dataSources.[n].collectionRegexfield to filter the collections only.
databases.[n].collections.[n].dataSourcesArray of objects where each object represents a
storesfederated database instance store to map with the collection.
databases.[n].collections.[n].dataSources.[n].storeNameName of a federated database instance store to map to the
<collection>. Must match thenameof an object in thestoresarray.
databases.[n].collections.[n].dataSources.[n].databaseName of the database on the Atlas cluster that contains the collection. You must omit this setting to:
Create a wildcard (
*) collection for a wilcard (*) database.Glob multiple databases.
databases.[n].collections.[n].dataSources.[n].databaseRegexOptional. Regex pattern to use for globbing databases to combine multiple collections. If you specify this option, the federated database instance instance contains a single database with collections from multiple databases. For globbing databases, you must do the following:
Omit the
databasefield.Specify a valid name for the
databases.[n].collections.[n].dataSources.[n].collectionfield.
Example
Suppose you have 2 databases named
fooandbarthat each have a collection namedSales. You can combine theSalescollection fromfooandbarusing thedatabaseRegexoption in your storage configuration:{ "databases": [ { "name": "Transactions", "collections": [ { "name": "AllSales", "dataSources": [ { "storeName": "atlasStore", "databaseRegex": ".*", "collection": "Sales" } ] } ] } ] } For the preceding
databasesobject, Atlas Data Federation generates the following in your federated database instance:A virtual database named
Transactions.A virtual collection named
AllSalesthat contains data from the collection namedSalesin all the databases whose name match the regex pattern specified in thedatabaseRegexoption.
If you specify this option, you must specify the name of the collection. You can't specify this option for wildcard collections.
databases.[n].collections.[n].dataSources.[n].collectionName of the collection in the Atlas cluster on which the federated database instance store is based. You must omit this setting for:
Creating a wildcard (
*) collection.Creating wildcard collection names that match regex patterns.
Combining multiple collections in a database using regex patterns.
databases.[n].collections.[n].dataSources.[n].collectionRegexConditional: Optional for wildcard collections, required for combining collections in a database.
Regex pattern to use for creating the wildcard (
*) collection or for combining mulitple collections in a database.To use regex patterns for wildcard (``*``) collection names, you must do the following:
Specify wildcard (
*) as the value fordatabases.[n].collections.[n].name.Omit
databases.[n].collections.[n].dataSources.[n].collection.
If you specify this field for generating wildcard collections, the federated database instance instance only contains collections with names that match the specified regular expression. The collections in the federated database instance storage configuration use their original names in the Atlas cluster.
To use regex patterns for combining multiple collections in a database, you must do the following:
Specify a name that isn't the wildcard (
*) as the value fordatabases.[n].collections.[n].name.Omit
databases.[n].collections.[n].dataSources.[n].collection.
If you specify this field for combining multiple collections, the collection in the federated database instance instance contains data from all the Atlas collections with names that match the specified regular expression. The collection in the federated database instance storage configuration uses the name that you specify as value for
databases.[n].collections.[n].name.To learn more about the regex syntax, see Go programming language.
databases.[n].collections.[n].dataSources.[n].provenanceFieldNameName for the field that includes the provenance of the documents in the results. If you specify this setting in the storage configuration, Atlas Data Federation returns the following fields for each document in the result:
Field NameDescriptionproviderProvider (
stores.[n].provider) in the federated database instance storage configurationclusterNameName of the Atlas cluster (
stores.[n].clusterName)databaseNameName of the database (
databases.[n].collections.[n].dataSources.[n].database) in the Atlas clustercollectionNameName of the collection (
databases.[n].collections.[n].name)You can't configure this setting using the Visual Editor in the Atlas UI.
databases.[n].viewsArray of objects where each object represents an aggregation pipeline on a collection. To learn more about views, see Views.
databases.[n].views.[n].sourceName of the source collection for the view. If you want to create a view with a $sql stage, you must omit this field as the SQL statement will specify the source collection.
databases.[n].views.[n].pipelineAggregation pipeline stage(s) to apply to the
sourcecollection. You can also create views using the $sql stage.