Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

clarity regarding mongoose documentation – connect returning connection array

I am using mongoose and referring to api https://mongoosejs.com/docs/api/mongoose.html

My package.json says "mongoose": "^7.4.0" so I am not sure which specific version I am on. Assuming it is 7.5.0, I am using connect call to connect to mongodb via mongoose

const connection = await mongoose.connect(process.env.DATABASE_URL);
          var localdbClient = connection.connections[0].client;

I can’t find where in the document it says that connection has connections array. Where is it mentioned? Is the type of connection[] a connection? This doesn’t say so – https://mongoosejs.com/docs/api/mongoose.html

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How should I refer to the api and definitions?

>Solution :

The connections array is documented here: https://mongoosejs.com/docs/api/mongoose.html#Mongoose.prototype.connections

But apparently, what you really want here is getClient():
https://mongoosejs.com/docs/api/connection.html#Connection.prototype.getClient()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading