I want to explore the new transaction feature of MongoDB and use Spring Data MongoDB. However, I get the exception message "Sessions are not supported by the MongoDB cluster to which this client is connected". Any hint regarding the config of MongoDB 3.7.9 is appreciated.
The stacktrace starts with:
com.mongodb.MongoClientException: Sessions are not supported by the MongoDB cluster to which this client is connected at com.mongodb.MongoClient.startSession(MongoClient.java:555) ~[mongodb-driver-3.8.0-beta2.jar:na] at org.springframework.data.mongodb.core.SimpleMongoDbFactory.getSession(SimpleMongoDbFactory.java:163) ~[spring-data-mongodb-2.1.0.DATAMONGO-1920-SNAPSHOT.jar:2.1.0.DATAMONGO-1920-SNAPSHOT]
MongoDB's server sessions, or logical sessions, are the underlying framework used by client sessions to support Causal Consistency and retryable writes.
Creating a cluster in MongoDBBy using the free tier, the default setup is to deploy a MongoDB cluster with a replica set. However, if you also want to enable sharding, then you have to enable this feature separately and specify the number of shards to have.
We were able to config in local as below
On Linux, a default /etc/mongod.conf configuration file is included when using a package manager to install MongoDB.
On Windows, a default <install directory>/bin/mongod.cfg configuration file is included during the installation
On macOS, a default /usr/local/etc/mongod.conf configuration file is included when installing from MongoDB’s official Homebrew tap.
Add the following config
replication:
oplogSizeMB: 128
replSetName: "rs0"
enableMajorityReadConcern: true
sudo service mongod restart;
mongo;
rs.initiate({
_id: "rs0",
version: 1,
members: [
{ _id: 0, host : "localhost:27017" }
]
}
)
check for the config to be enabled
rs.conf()
we can use the connection URL as
mongodb://localhost/default?ssl=false&replicaSet=rs0&readPreference=primary
docs: config-options single-instance-replication
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With