Doubts about nodejs Developing mongoose to Manage mongodb Database?

  node.js, question

I just started to learn nodejs by myself, using mongodb database and mongoose to operate the database.

In a js file, when is the best time to open a database connection?
Is to open the database connection first, and then write all other pages get, render in it; Or do you want to get it first and then open it when you use the database?

If you link again when you use it, does it mean that every time you open the linked operation database, you must first establish Schema, then Model, then materialise, and finally save it?
I wrote Schema indb.once("open", function () {})I found that I couldn’t get Schema, so I had to write it again.
If the Schema structure is more complex, it would be too Against Nature to write it again every time the connection is made.

First, mongoose’s Schema can be hung on a connection
We are in the overall situation:const Model = mongoose.model('Story', aSchema)
Let’s say this when the app starts.mongoose.connect(uri)Just fine

I have never been worried about disconnection, reconnection, heartbeat maintenance, etc. This is also mongoose’s good point.
Also don’t have to think about when should disconnect.