MongoDS
MongoDB Client Encapsulation - MongoDS
Introduction
This is an encapsulation of the MongoDB client. The client needs to introduce the dependencies by themselves.
Usage
Introducing Dependencies
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.10</version>
</dependency>
Configuration
Create a mongo.setting
file in the config
directory under the ClassPath (or src/main/resources
):
# The maximum number of connections allowed per host (connection pool size). When the connection pool is exhausted, it will be blocked. The default is 10. --int
connectionsPerHost=100
# The number of thread queues. Multiplying this value by the value of connectionsPerHost gives the maximum thread queue size. If the connection thread queue is full, it will throw a "Out of semaphores to get db" error. --int
threadsAllowedToBlockForConnectionMultiplier=10
# The maximum wait time for a blocked thread to get a connection from the connection pool (in milliseconds). --int
maxWaitTime = 120000
# The timeout time when establishing a socket connection (in milliseconds). The default is 0 (infinite). --int
connectTimeout=0
# The socket timeout time; this value will be passed to Socket.setSoTimeout(int). The default is 0 (infinite). --int
socketTimeout=0
# Whether to enable long connections. Defaults to false. --boolean
socketKeepAlive=false
#---------------------------------- MongoDB instance connection
[master]
host = 127.0.0.1:27017
[slave]
host = 127.0.0.1:27018
#-----------------------------------------------------
Usage
// Combine master and slave to form a master-slave cluster
MongoDatabase db = MongoFactory.getDS("master", "slave").getDb("test");