0

im trying to connect my node app to mongo cluster, and i have used this method

var options = {
 useMongoClient: true,
 autoIndex: false, 
 reconnectTries: Number.MAX_VALUE, 
 reconnectInterval: 500, 
 poolSize: 10, 
 bufferMaxEntries: 0
};

var cluster = "my cluster url XXX";
mongoose.connect(cluster, options);

but it throwing this error

(node:8701) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): MongoError: topology was destroyed (node:8701) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that a re not handled will terminate the Node.js process with a non-zero exit code.

I know this is not the right way to connect to a cluster. can anyone please tell me which is the best method and why (with an example) Thanks!!

Desmond Dias
  • 51
  • 10
  • 1
    Possible duplicate of: https://stackoverflow.com/questions/30909492/mongoerror-topology-was-destroyed – kentor Dec 01 '17 at 07:10
  • 1
    Possible duplicate of [mongoError: Topology was destroyed](https://stackoverflow.com/questions/30909492/mongoerror-topology-was-destroyed) – kentor Dec 01 '17 at 07:10

1 Answers1

0

Try:

mongoose.connect('mongodb://'+ip+':'+port+'/'+database, function(err) {});
mongoose.connection.on('connected', function () {});
mongoose.connection.on('disconnected', function () {});
RaphaMex
  • 2,781
  • 1
  • 14
  • 30