Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-2818

When performing some Init stuff, got "MongoError: not master" error

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.3
    • Affects Version/s: None
    • Component/s: None
    • None

      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.

            Assignee:
            thomas.reggi@mongodb.com Thomas Reggi (Inactive)
            Reporter:
            nikhil.singh@mongodb.com Nikhil Singh
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: