1. Database (MongoDB) connection
(1) Install App Builder Express
NPM Install Express-generator-g
(2) Create an app
Express App Name
(3) Installing the MongoDB module
NPM Install MongoDB
(4) Page rendering type converted to HTML
A. Loading Ejs
1) npm Install Ejs
B.app.js Configuration
1) app.set (' View ', Path.join (__dirname, ' views '));
2) app.engine (' HTML ', require (' Ejs '). RenderFile);
3) App.set (' View engine ', ' html ');
Red Box switch
C. Change the jade file suffix in the views file under the application file to HTML
(5) Database connection
A. In the Application Folder cmd enter NPM start (provided that the MongoDB service is started)
No MongoDB Click here to open link * * *
2. Database (MongoDB) operations
(1) Creating a MongoDB database collection
Run MongoDB file path after starting MongoDB service +bin\mongo.exe
After performing show DBS you can see all the libraries of the service
Show Collections View All collections
Green is the newly created library
(2) inserting a document
Insertone can only insert one piece of data
Insertmany inserting more than one data
View data first switch library use library name
then query db. Collection name. Find ()
(3) Query data
CMD in Db.site.find () or Db.site.find (). ToArray ()
The others are not listed here Click here to open the link *****************
NODE+MONGODB Operating Database