Q. What connection options should I include when calling mongoose.connect(…)?

A: Some useful options include:

  • useNewUrlParser: true and useUnifiedTopology: true (to opt into newer Mongo driver behavior) 
  • dbName to override default DB 
  • autoIndex: false in production (to avoid performance issues building indexes automatically) 
  • maxPoolSize, minPoolSize to tune pooling 
  • serverSelectionTimeoutMS to limit how long it tries to find a server
    Also, Mongoose buffers queries until the connection is ready by default. You can disable buffering (via bufferCommands:false) if needed.
Back To Top