Connected to a database 5 ~ express ~

1. Create users.js file in the directory schema, database module is operated by mongoose 

2, before defining the users table structure, application support or need to connect to the database. So to be reproduced in an application database file app.js inlet (i.e. loading database)

3 ,    var mongoose = require('mongoose')

4, mongoose.connect () // connect to the database.

5, before the need to open the database connection,

 (1) cmd into the E: \ MongoDB \ Server \ 4.0 \ bin directory E: \ MongoDB \ Server \ 4.0 \ bin> mongod (need to set parameters before executing the details, see 1.5.2,1.5.3)

    (2) specify the database storage path: The database directory of the project.   

    (3) designated port

 (4)  执行    =》    PS E:\MongoDB\Server\4.0\bin> mongod --dbpath=D:\node\blog\blog-2\db --port=27018

 (5) may also be connected through a visual tool mongodb

Guess you like

Origin www.cnblogs.com/500m/p/10988105.html