Hi,
HighLevel Problem statement: We are getting the exception “com.mongodb.MongoClientException: Sessions are not supported by the MongoDB” while creating the session from the MongoClient API when using ReactiveStreams MongoDB Java driver version 3.6.0.
Recently we migrated from MongoDB version 2.6 to 3.6 and We used ReactiveStreams MongoDB Java driver version 3.6.0 to create session out of MongoClient API.
Creation of session failed with “Sessions are not supported by the MongoDB”.
However from the mongo shell, we can see the replica set status and in fact was able to execute db.getMongo().startSession() successfully.
We tested the same by created a new instance of MongoDB version 3.6 directly and this time MongoClient api was able to create the session with out issues.
Not sure why session is not getting created while in the migration environment.
Is it the issue with the migration? or with the driver?
Any help on this.
Java code Snippet:
MongoClient client;
ClientSession clientSession = null;
MongoDatabase mongoDatabase = null;
MongoCollection<Document> fromCollection = null;
Builder clientBuilder = null;
MongoClientSettings settings = null;
ConnectionString conn = null;
clientBuilder = MongoClientSettings.builder();
conn = new ConnectionString(clientURI);
clientBuilder = clientBuilder.applyConnectionString(conn);
settings = clientBuilder.retryReads(true).readPreference(ReadPreference.primary()).build();
client = MongoClients.create(settings);
Publisher<ClientSession> session = client.startSession(); // fails here
MongoDBOperationsSubscriber<ClientSession> sub = new
MongoDBOperationsSubscriber<>();
sub.setCallingMethodName(“ClientSession”);
session.subscribe(sub);
if (sub.hasErrors()) {
sub.cancelSubscription();
System.out.println(
“Error occurred when MongoDBOperationsSubscriber is
receiving the documents from publisher.“);
System.out.println(“Error is [ ” + sub.getError().getMessage() +
” ].“);
throw new MongoDBCaptureException(sub.getError().getMessage());
}
if(!sub.getData().isEmpty()) {
clientSession = sub.getData().get(0);
}
MongoShell outputs:
rs01:PRIMARY> rs.conf();
{
“_id” : “rs01",
“version” : 25828,
“protocolVersion” : NumberLong(1),
“members” : [
{
“_id” : 5,
“host” : “mongodb03:27017",
“arbiterOnly” : false,
“buildIndexes” : true,
“hidden” : true,
“priority” : 0,
“tags” : {
},
“slaveDelay” : NumberLong(0),
“votes” : 1
},
{
“_id” : 8,
“host” : “mongodb02:27017",
“arbiterOnly” : false,
“buildIndexes” : true,
“hidden” : true,
“priority” : 0,
“tags” : {
},
“slaveDelay” : NumberLong(0),
“votes” : 1
},
{
“_id” : 9,
“host” : “mongodb04:27017",
“arbiterOnly” : false,
“buildIndexes” : true,
“hidden” : false,
“priority” : 4,
“tags” : {
},
“slaveDelay” : NumberLong(0),
“votes” : 1
},
{
“_id” : 12,
“host” : “mongodb05:27017",
“arbiterOnly” : false,
“buildIndexes” : true,
“hidden” : false,
“priority” : 2,
“tags” : {
},
“slaveDelay” : NumberLong(0),
“votes” : 1
},
{
“_id” : 13,
“host” : “mongodb06:27017",
“arbiterOnly” : false,
“buildIndexes” : true,
“hidden” : false,
“priority” : 2,
“tags” : {
},
“slaveDelay” : NumberLong(0),
“votes” : 1
}
],
“settings” : {
“chainingAllowed” : true,
“heartbeatIntervalMillis” : 2000,
“heartbeatTimeoutSecs” : 10,
“electionTimeoutMillis” : 10000,
“catchUpTimeoutMillis” : 60000,
“catchUpTakeoverDelayMillis” : 30000,
“getLastErrorModes” : {
},
“getLastErrorDefaults” : {
“w” : 1,
“wtimeout” : 0
}
}
}
MongoDB logs has this message:
{“log”:“2023-03-03T06:44:44.298+0000 I CONTROL [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist\n”,“stream”:“stdout”,“time”:“2023-03-03T06:44:44.298265861Z”}