Potentially unhandled rejection [3000] MongoError: not master

46 views
Skip to first unread message

Astro

unread,
May 19, 2016, 5:06:01 AM5/19/16
to mongodb-user
We are running into Potentially unhandled rejection [3000] MongoError: not master when using replica set with node.js code

Using npm mongodb module version 2.1.19.

When an application tries to insert/update/delete documents, the above error is thrown in error logs. However, documents are inserted/updated to mongodb.

This happens only when the readPreference is set to secondaryPreferred. 

No error is thrown when readPreference is set to primary.

Any help would be appreciated.

Astro

unread,
May 20, 2016, 1:21:40 PM5/20/16
to mongodb-user
 .
 
Any help on this?

Kevin Adistambha

unread,
May 24, 2016, 2:15:21 AM5/24/16
to mongodb-user

Hi,

I was able to successfully insert, update, and delete a document using the secondaryPreferred readPreference using MongoDB 3.2.6 and node.js driver 2.1.19:

var MongoClient = require('mongodb').MongoClient
var assert = require('assert')
MongoClient.connect('mongodb://localhost:27017,localhost:27018,localhost:27019',  {db: {readPreference: 'secondaryPreferred'}} , function(err,db){
    assert.equal(null,err,err)
    var coll = db.db('test').collection('test')
    coll.insert({x:1}, function(err,res){
        assert.equal(null,err,'Insert: ' + err)
        console.log('Insert successful')
    })
    coll.updateOne({x:1}, {$set: {x:2}}, function(err,res){
        assert.equal(null,err,'Update: ' + err)
        console.log('Update successful')
    })
    coll.deleteOne({x:2}, function(err,res){
        assert.equal(null,err,'Delete: ' + err)
        console.log('Delete successful')
    })
})

If you are still having not master issues, could you please post your MongoDB version and a code snippet that reproduces the issue?

Also please note that there was a recently-solved ticket that involves the not master error when dropping a collection using secondaryPreferred (NODE-716) that will be fixed in the upcoming node.js driver update.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages