Mongodb-memory-server: Does it support Mongodb multi document transaction?

Created on 11 Feb 2020  路  12Comments  路  Source: nodkz/mongodb-memory-server

Getting below error message:
MongoError: Transaction numbers are only allowed on a replica set member or mongos

Versions

  • NodeJS: v10.13.0
  • mongodb-memory-server-*: 6.2.4
  • mongodb: 3.5.2
  • mongoose: 5.8.11
  • system: MacOS

package: mongo-memory-server

What is your question?

Does it support Mongodb multi document transaction?

question

Most helpful comment

Yep, supports!

Read docs about How to start ReplicaSet

All 12 comments

Yep, supports!

Read docs about How to start ReplicaSet

@nodkz Any suggestions how to solve the error "MongoError: Transaction numbers are only allowed on a replica set member or mongos".

Error stack:
MongoError: Transaction numbers are only allowed on a replica set member or mongos
at Connection. (/Users/onkar/html/app-project/api/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:466:61)
at Connection.emit (events.js:182:13)
at Connection.EventEmitter.emit (domain.js:442:20)
at processMessage (/Users/onkar/html/app-project/api/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connection.js:384:10)
at Socket. (/Users/onkar/html/app-project/api/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connection.js:553:15)
at Socket.emit (events.js:182:13)
at Socket.EventEmitter.emit (domain.js:442:20)
at addChunk (_stream_readable.js:283:12)
at readableAddChunk (_stream_readable.js:264:11)
at Socket.Readable.push (_stream_readable.js:219:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

@onkarjanwa

"MongoError: Transaction numbers are only allowed on a replica set member or mongos"

means that it is only allowed on an replica set or an mongos instance, so you need to spin up multiple instances
@nodkz already provided an link to the documentation on how to start an replica set with mongo-memory-server

@hasezoey @nodkz Multi document transactions are working on local machine without any replica set. But when using mongo-memory-server for test environment it is throwing error.

I could not get it working even after using MongoMemoryReplicaSet, every time it throws a new error.

@onkarjanwa do you use by any chance an non 4.0+ version of mongodb (default being 3.2)? when yes, please set the version to 4.0+ in order to use document transactions

@hasezoey

I am using binary version 4.2.3 while creating MongoMemoryServer.

@onkarjanwa just to confirm, is this the actual version printed in the log, or just the set version? (if unsure, delete the binary and let it re-download)
otherwise i dont know, because i dont know much about document transactions and replica sets

@hasezoey I have set the version to 4.2.3 and it downloads new binary and installs it.

@onkarjanwa sorry, then i dont have any more advice / questions, i never worked with replica sets and document transactions

@hasezoey ok, thanks :)

I cant seem to get it to work in the testing environment as well. Fails when running startTransaction

@onkarjanwa sorry, then i dont have any more advice / questions, i never worked with replica sets and document transactions

To support multi-document transaction, we just need to set storageEngine: 'wiredTiger'

    const mongoServer = new MongoMemoryReplSet({
      replSet: { count: 1, storageEngine: 'wiredTiger' },
    })

Found the fix via this SO question

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wu-json picture wu-json  路  8Comments

frederikheld picture frederikheld  路  6Comments

pedrokohler picture pedrokohler  路  9Comments

yavorski picture yavorski  路  6Comments

elreeda picture elreeda  路  3Comments