mongo-java-driver reports "Sessions are not supported by the MongoDB cluster to which this client is connected" with single instance

3,448 views
Skip to first unread message

Nikolay Firov

unread,
Oct 17, 2019, 7:56:14 PM10/17/19
to mongodb-user
Hello, i am using local docker mongo v4.2, which supports sessions and transactions:

$ mongo
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017
Implicit session: session { "id" : UUID("a1329475-236c-4a2d-bde6-9118cf717c85") }
MongoDB server version: 4.2.0

...

> session = db.getMongo().startSession()
session { "id" : UUID("7327964d-13d1-4d3f-bc63-2ac031c4f032") }
> session.startTransaction()
>

but when i connect from java, i got error: Sessions are not supported by the MongoDB cluster to which this client is connected at com.mongodb.MongoClient.startSession(MongoClient.java:582) ~[mongo-java-driver-3.11.1.jar:?]

SO suggests replica set https://stackoverflow.com/questions/50255195/how-to-configure-a-mongodb-cluster-which-supports-sessions, but i think it should work with single instance.

Kevin Adistambha

unread,
Oct 29, 2019, 8:03:17 PM10/29/19
to mongodb-user

Hi Nikolay,

SO suggests replica set https://stackoverflow.com/questions/50255195/how-to-configure-a-mongodb-cluster-which-supports-sessions, but i think it should work with single instance.

As mentioned in the SO answer and the Transactions page, multi document transactions are not supported in a non replica set deployment since the feature depends on the existence of the oplog. This is by design, and there is no “workaround” to make transactions work with a standalone deployment.

If you need a testing deployment, you can create a single-node replica set by starting the mongod with the replSet parameter, initiate the set using that one node, and don’t add any more node to the set. For testing purposes, single node replica set is fine, although it’s strongly not recommended to run any kind of production work on this setup.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages