Express and Mongodb
2017-09-06 本文已影响0人
Komolei
Today,I learn the Express frame and the Mongodb which is a noSQL database.
- If you want learn MongoDB, you should deploy MongoDB first! install,to select you computer system version. So I choose the Window Server 2008.
- Finish the download files, you should install
- when you finish installing,you need run command window ,in the Window system,
cmd
- rember you should choose a disk to run
mkdir data
andmkdir log mkdir db
in the data directory ,finally,cd log
andtouch mongodb.log
;
for me ,I choose the C disk to run command - ok,run `mongod --dbpath "C:\data\db" --logpath "C:data\log\mongodb.log" --serviceName "MongoDB" --install
- run
net start MongoDB
//to start service . if you stop service ,runnet stop MongoDB
- maybe you will meet trouble,like
can't find net
, so should add environment path to relative MongDB,to input C:\Program Files\MongoDB\Server\3.4\bin
in the path option. - now ,run
mongo
// this will show the connection success
Mongo Database
-
use [databaseName]
insert dataBase show dbs
show collections
-
show tables
// deletedb.collections.drop()
-
use [database name]
to insert a database , -
db.runoob.insert({})
; ---insert data db.runoob.find()
db.runoob.update()
-
db.dropDatabse()
-- to delete a database
waiting for updateing
Express
I advise to learn document of Express Chinese version
Update 📌11/25.2017
the command of the mongoDB
1. db.tablename.find().pretty()
2. db.tablename.stats;
3. var users=db.users;user.find().pretty();//can show the all record of db.users this table
the prototype of ObjectId is only.
var Id=new ObjectId();
Id //show some result