For the time being
For the time being
Please watch the above picture carefully. You have noticed the output of the white MongoDb Connected successfully in the last line. Yes, this output tells us that our database was connected at this time, and that our database was connected after executing the Schema we wrote before. Therefore, the Schema in the code reported an error and could not find the collection we defined.
Solution: We need to make the database link before executing our Schema code. If this is a personal exercise, we recommend waiting for the database link to succeed before operating the browser.
Personally, I suggest that when connecting to the database during the practice of Mongoose, a state should be output when connecting to the database successfully, so as to facilitate myself to know the state of the database. I asked the leader of the backend, and he told me that when the project is online, the database will not be unlinked unless the server crashes. Of course, some companies may shut down the database when they do not need it for optimization, which I think is almost rare, after all, the frequent operation of the database, the performance consumption is not low. At present, I am just a novice among novices for Mongoose. How to deal with Mongoose. Conntect will be a matter for you to explore, because I am just practicing to insert data into the database, and I just need to wait for the database link and refresh the browser to insert data perfectly. Of course, IF there is a need to dynamically insert data in the later period, I have a solution to deal with it. I will add the solution to the bottom of this article. If there is any mistake, please contact me in time.
Finally, I do not want someone to reprint my article, because I do not want to search a pile of other articles are the same, support the original! It is strictly prohibited to reprint