////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

== Multiple Data Sources
GORM for MongoDB supports the notion of multiple data sources where multiple individual `MongoClient` instances can be configured and switched between.

=== Configuring Multiple Mongo Clients

include::configuration.adoc[]

=== Mapping Domain Classes to Mongo Clients

include::mappingDomainsToDataSources.adoc[]

=== Switching between Mongo Clients

include::mongoClientSwitching.adoc[]

[[connectionSources]]
=== The ConnectionSources API

Introduced in GORM 6.0, the link:../api/org/grails/datastore/mapping/core/connections/ConnectionSources.html[ConnectionSources] API allows you to introspect the data sources configured for the application:

[source,groovy]
----
@Autowired
MongoDatastore mongoDatastore
...
ConnectionSources<MongoClient, MongoConnectionSourceSettings> connectionSources
					= mongoDatastore.getConnectionSources()

for(ConnectionSource<MongoClient, MongoConnectionSourceSettings> connectionSource in connectionSources) {
	println "Name $connectionSource.name"
	MongoClient mongoClient = connectionSource.source
}
----
