Connection.prototype.setClient()

Returns:
  • «Connection» this

Set the MongoDB driver MongoClient instance that this connection uses to talk to MongoDB. This is useful if you already have a MongoClient instance, and want to reuse it.

Example:

  1. const client = await mongodb.MongoClient.connect('mongodb://localhost:27017/test');
  2. const conn = mongoose.createConnection().setClient(client);
  3. conn.getClient(); // MongoClient { ... }
  4. conn.readyState; // 1, means 'CONNECTED'