1.MongoDB Download Install E:\MongoDB
2. Where to create the database file E:\MongoDB\data\db
3. Start MongoDB Service
Library operations
New database: The first step: Use the new database name; second step: Do the library related operations; If you do not take the second step, the database will not be created
View database: Show DBS;
New table: Db.createcollection (' new table name to be created ');
View current database table below: Show collections;
Deletes the current database specified table: DB. Table name. Drop ();
Delete Current database: Db.dropdatabase ();
---------------------------------------------------------------I'm a split line------------------------------------------------------
Write a simple demo below.
1.express Creating E:\test Projects
Don't point this
2. Create a database
E:\MongoDB\bin Start Mongo.exe
Input
Use text \ Create a database called text
Db.createcollection ("users") \ Create a collection
Db.users.insert ({"Name": "admin", "Password": "111"}) \ adds a document to the Users collection.
Db.users.find () \ Query the document you added
3. Project Connection Database
Create a folder under the project root directory database, and then create a db.js E:\test \ Database\db.js
[HTML] View plain copy
var mongoose = require (' Mongoose ');
var db = mongoose.connect (' Mongodb://localhost/text ');//; Connect to database
var Schema = Mongoose. Schema; Create a model
var userschema = new Schema ({
Name:string,
Password:string
}); A new model has been defined, but this pattern has not been associated with the Users collection
Exports.user = Db.model (' users ', userschema);//associated with the Users collection
4.views Folder CREATE View file
5. Control of routing
Index.js in the routes file
6. Start the node server
View in Http://localhost:3000/
Demo File: Https://github.com/MMMsCheng/nodedemoLogin
node. JS development----Create and connect database MongoDB