ReplicaSet throws error while creating: MongoError: not master
See original GitHub issueVersions
- NodeJS: 14.17.5
- mongodb-memory-server-*: 7.3.6
- mongodb(the binary version): 4.4.4
- system: MacOS
package: mongo-memory-server
What is the Problem?
When I try to create MongoMemoryReplSet
I get MongoError: not master
, but this seems to happen only when I’m running at least two test files in jest.
This is the exact error that I get:
MongoError: not master
at MessageStream.messageHandler (node_modules/mongodb/lib/cmap/connection.js:268:20)
at processIncomingData (node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (node_modules/mongodb/lib/cmap/message_stream.js:42:5)
Update 1
Sometimes, there is no error, just timeouts from all tests…
Update 2
I just received a bit more detailed stacktrace:
MongoError: not master
at MessageStream.messageHandler (/Users/mateuszlewandowski/Projects/konsalnet/konsalnet/scheduling-api/node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:400:28)
at MessageStream.emit (domain.js:470:12)
at processIncomingData (/Users/mateuszlewandowski/Projects/konsalnet/konsalnet/scheduling-api/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/Users/mateuszlewandowski/Projects/konsalnet/konsalnet/scheduling-api/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at Socket.ondata (internal/streams/readable.js:726:22)
at Socket.emit (events.js:400:28)
at Socket.emit (domain.js:470:12)
at addChunk (internal/streams/readable.js:290:12)
at readableAddChunk (internal/streams/readable.js:265:9)
at Socket.Readable.push (internal/streams/readable.js:204:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
Code Example
Setup code
let mongoServer;
export async function setupTestDatabase() {
mongoServer = await MongoMemoryReplSet.create({ replSet: { count: 3, storageEngine: "wiredTiger" } });
await mongoServer.waitUntilRunning();
const mongoUri = mongoServer.getUri();
await connect(mongoUri, "test-db"); // <- creates mongo client and connects to database, client is then imported in other files
}
export async function tearDownTestDatabase() {
await disconnect(); // <- disconnects application from mongo
await mongoServer?.stop();
}
and in each test file I have
beforeAll(() => setupTestDatabase());
afterAll(() => tearDownTestDatabase());
Issue Analytics
- State:
- Created 2 years ago
- Comments:20
Top Results From Across the Web
MongoError: not master - node.js - Stack Overflow
js app to MongoDB having replica set but it's throwing an error when any write operations are performed. It throws MongoError: not master....
Read more >not master and slaveOk=false, Code: 13435 connection error
This error means you are trying to read from a secondary replica set member. But the secondary member (the Slave) is not setup...
Read more >MongoDB error not master and slaveOk=false - Hackolade
If you get an error "not master and slaveOk=false" when connecting to a MongoDB instance, on a secondary member (for example, a replica...
Read more >'not master and slaveOk=false' error connecting with Compass
Getting this error connecting with Compass! An error occurred while loading navigation: 'not master and slaveOk=false': It is recommended to ...
Read more >"errmsg" : "not master" while submitting mongodb commands
Only one of the replicasets can act on write operations and this is called "primary" or "master". This error simply means your command/query ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
i did not get a response yet for https://github.com/nodkz/mongodb-memory-server/issues/535#issuecomment-907793148, but a small update: version 8.0.0 released yesterday, which upgraded mongod (driver) and default mongodb binary versions, could you maybe try that?
See Migrate 8
Closing Issue because it is marked as stale