To use multiple databases you can use connect() and provide
an alias name for the connection - if no alias is provided then “default”
is used.

In the background this uses register_connection() to
store the data and you can register all aliases up front if required.

Individual documents can also support multiple databases by providing a
db_alias in their meta data. This allows DBRef
objects to point across databases and collections. Below is an example schema,
using 3 different databases to store data:

Sometimes you may want to switch the database or collection to query against.
For example, archiving older data into a separate database for performance
reasons or writing functions that dynamically choose collections to write
a document to.