Details
-
Task
-
Resolution: Fixed
-
Major - P3
-
None
-
None
-
None
-
(copied to CRM)
-
Empty show more show less
Description
Hi Team,
The customer is running the below script to initialize collections and indexes and is getting the error
MongoError: not master
|
The script is
const client = await MongoClient.connect(this.mongoConfig.url(), {
|
useNewUrlParser: true,
|
ignoreUndefined: true,
|
useUnifiedTopology: true,
|
readPreference: ReadPreference.SECONDARY_PREFERRED,
|
});
|
|
getCollection(name: string): Collection {
|
// Prioritize safety over speed
|
// Ensures enough nodes have really written the data.
|
// Set default write concern to majority, wait for journal to be written and set a write timeout instead of infinite.
|
const options: DbCollectionOptions = {
|
w: "majority",
|
j: true,
|
wtimeout: 5000,
|
};
|
|
return this.database.collection(name, options, (error, collection) => {
|
if (error) {
|
throw error;
|
}
|
return collection;
|
});
|
}
|
- MongoDB Driver:node-mongodb-native v3.6.0
- Cluster - opus
- The connection string used is the SRV string.
I asked the customer to remove the readPreference: ReadPreference.SECONDARY_PREFERRED, but they insisted that it works on other cluster in different projects so they cannot change it.
Attachments
Issue Links
- is duplicated by
-
NODE-2784 MongoError: Not Master when running createIndex in 3.6.0
-
- Closed
-