The model catalog is primarily packaged with some frequently used methods for ease of use.
Setting.js file:
Very simple, just encapsulate a URL as a public, later change is easy to change.
Md5.js (not recommended):
Db.js file:
Db.js files mainly encapsulate some connection operations to the database, otherwise writing on router.js will result in very large code redundancy and the same code.
For database operations, the first step is of course to connect to the database:
__connectdb as an intrinsic function, convenient to be referenced.
Then connect to the database using the method provided by Mongoclient.connect, connect receives two parameters (address, callback function)
Increase:
Inserting data into a database, of course, cannot limit only one, and certainly multiple data insertions.
So the Insertone function receives three parameters (database name, JSON to store, callback function)
You must close the database every time you do an operation on the database and after you have done it.
Why? Because each connection has a certain amount of pressure on the database, the database will be a catastrophic card if these idle pressures are not released.
Check:
Here I am divided into two parts.
The first part (make a judgment, judge the number of arguments that are coming)
Part II (Query database):
By deleting:
Removed from the database. Receive parameters (database name, JSON to delete, callback function)
Each operation requires a callback function to close the database.
Repair:
The Updatemany method receives four parameters (database name, JSON to be modified, modified JSON, callback function)
Finally, you close the database.
Paging:
The data that is queried must be paged out. So this function is also available.
Above..
Build a personal blog with Node.js+mongodb (model directory) (iii)