Help setting up a development replica set with transactions for Mongoid

Hello!

I want to use the Transactions with Sessions feature on the Mongoid, the officially supported object-document mapper (ODM) for MongoDB in Ruby.

To make this possible, I already did setup a Replica Set on my system, following this tutorial:
http://blog.rueckstiess.com/mtools/mlaunch.html

About the topology , I am currently using the default configuration of this tutorial => http://blog.rueckstiess.com/mtools/mlaunch.html

mlaunch --replicaset

Therefore, I am starting a replica set with (by default) 3 nodes on ports 27017 , 27018 , 27019 .

However, I am having some problems when I try to invoke sessions on the ruby code. The error message says: “A session was attempted to be used with a MongoDB server version that doesn’t support sessions. Sessions are supported in MongoDB server versions 3.6 and higher.”. However, when I call db.version() , I can see it is on version 4.2.3 already

  • Steps to reproduce the error:
  1. Enter on rails console
rails c
  1. Try to execute this code
Project.with_session do |session|
  session.start_transaction
  Project.create!(name: 'Example')
  session.commit_transaction
end
  1. The result here is the following error message
Mongoid::Errors::InvalidSessionUse:
message:
  Sessions are not supported by the connected server(s).
summary:
  A session was attempted to be used with a MongoDB server version that doesn't support sessions. Sessions are supported in MongoDB server versions 3.6 and higher.
resolution:
  Verify that all servers in your deployment are at least version 3.6 or don't attempt to use sessions with older server versions.
from /Users/victor/.rvm/gems/ruby-2.6.5@pocket/gems/mongoid-7.0.5/lib/mongoid/clients/sessions.rb:98:in `rescue in with_session'
Caused by Mongo::Error::InvalidSession: Sessions are not supported by the connected servers.
from /Users/victor/.rvm/gems/ruby-2.6.5@pocket/gems/mongo-2.12.1/lib/mongo/client.rb:865:in `start_session'

:information_source: Some additional infos…

  • My Replica Sets setup
$ mlaunch list

PROCESS    PORT     STATUS     PID

mongod     27017    running    -
mongod     27018    running    33353
mongod     27019    running    33356
  • My mongoid.yml file config
development:
  clients:
    default:
      database: pocket_api_development
      hosts:
        - "<%= ENV["MONGO_HOST"] %>:27017"
      options:
        user: 'root'
        password: 'ri8Oogu6'
        auth_source: admin
        replica_set: replset
  options:
test:
  clients:
    default:
      database: pocket_api_test
      hosts:
        - "<%= ENV["MONGO_HOST"] %>:27017"
      options:
        read:
          mode: :primary
        max_pool_size: 1
        user: 'root'
        password: 'ri8Oogu6'
        auth_source: admin
  • The Storage Engines
mongo --port 27017
> db.serverStatus().storageEngine
{
  "name" : "wiredTiger",
  "supportsCommittedReads" : true,
  "oldestRequiredTimestampForCrashRecovery" : Timestamp(0, 0),
  "supportsPendingDrops" : true,
  "dropPendingIdents" : NumberLong(0),
  "supportsSnapshotReadConcern" : true,
  "readOnly" : false,
  "persistent" : true,
  "backupCursorOpen" : false
}
mongo --port 27018
replset:PRIMARY> db.serverStatus().storageEngine
{
  "name" : "wiredTiger",
  "supportsCommittedReads" : true,
  "oldestRequiredTimestampForCrashRecovery" : Timestamp(1595260796, 1),
  "supportsPendingDrops" : true,
  "dropPendingIdents" : NumberLong(0),
  "supportsSnapshotReadConcern" : true,
  "readOnly" : false,
  "persistent" : true,
  "backupCursorOpen" : false
}
mongo --port 27019
> db.serverStatus().storageEngine
{
  "name" : "wiredTiger",
  "supportsCommittedReads" : true,
  "oldestRequiredTimestampForCrashRecovery" : Timestamp(0, 0),
  "supportsPendingDrops" : true,
  "dropPendingIdents" : NumberLong(0),
  "supportsSnapshotReadConcern" : true,
  "readOnly" : false,
  "persistent" : true,
  "backupCursorOpen" : false
}

@Victor_Costa,

What is the mongoid version you are using?

Can you run any other commands without explicit sessions?
Have you tested specifying all 3 hosts in connection conf?

I would suggest doing our atlas guide while using an Atlas free cluster rather then mlaunch…

Please upload the rs.status() and logs.

Best regards
Pavel