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

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

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.6.3
    • None
    • None

    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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: