Getting below error message:
MongoError: Transaction numbers are only allowed on a replica set member or mongos
package: mongo-memory-server
Does it support Mongodb multi document transaction?
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.
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.
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
Most helpful comment
Yep, supports!
Read docs about How to start ReplicaSet