Using MongoSwift in Mulithreaded Applications
As of MongoSwift 0.2.0, the following types are safe to use across threads:
We make no guarantees about the safety of using any other type across threads.
MongoClient is backed by a pool of server connections. Any time a client or one of its child objects (a
MongoCollection) makes a request to the database (a
insertOne, etc.) a connection will be retrieved from the pool, used to execute the operation, and then returned to the pool when it is finished.
MongoClient uses its own background thread to monitor the MongoDB topology you are connected to.
In order to share the connection pool across threads and minimize the number of background monitoring threads, we recommend sharing
MongoClients across threads.
Usage With Server-side Swift Frameworks
Examples/ directory in the driver GitHub repository for examples of how to integrate the driver in multithreaded frameworks.