title: MongoError: not master
body: <p>I am trying to connect node.js app to MongoDB having replica set but it's throwing an error when any write operations are performed.</p>
  
  <p>It throws MongoError: not master. </p>
  
  <p>It tries to write on secondary mongo instances.</p>
  
  <p>I have the options as { db: { readPreference: secondaryPreferred } } and passing it to the function MongoClient.connect in the node.js code using native Mongo Driver.</p>
  
  <p>The URL used to connect looks like mongodb://admin:pass@host_one:27017,host_two:27017,host_three:27017/dbName</p>
  
  <p>Any help would be really appreciated.</p>