Microsoft Windows [版本 10.0.17134.950]
(c) 2018 Microsoft Corporation。保留所有权利。
C:\Users\天主极乐大帝>d:
1、进入bin目录
D:\>cd D:\MongoDB\Server\3.4\bin
D:\MongoDB\Server\3.4\bin>mongod --config "D:\MongoDB\Server\3.4\mongo.config" --install --serviceName "MongoDB"
2019-09-04T11:30:58.433+0800 I CONTROL [main] log file "D:\MongoDB\Server\3.4\data\log\mongo.log" exists; moved to "D:\MongoDB\Server\3.4\data\log\mongo.log.2019-09-04T03-30-58".
2、命令行启动mongo
D:\MongoDB\Server\3.4\bin>mongo
MongoDB shell version v3.4.16-41-g83c3022fe4
connecting to: mongodb://127.0.0.1:27017
2019-09-04T11:33:05.665+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2019-09-04T11:33:05.665+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:240:13
@(connect):1:6
exception: connect failed
D:\MongoDB\Server\3.4\bin>mongo
MongoDB shell version v3.4.16-41-g83c3022fe4
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.16-41-g83c3022fe4
Server has startup warnings:
2019-09-03T20:34:03.839-0700 I CONTROL [initandlisten]
2019-09-03T20:34:03.839-0700 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-09-03T20:34:03.840-0700 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-09-03T20:34:03.840-0700 I CONTROL [initandlisten]
3、进入tzl数据库
> use tzl switched to db tzl
4、显示数据库
> show dbs
admin 0.000GB
local 0.000GB
lys 0.000GB
newtestdb 0.000GB
test 0.000GB
> use tzl
switched to db tzl
5、向tzl数据表中插入一条数据
> db.tzl.insert({'name':'liyisong'})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
local 0.000GB
lys 0.000GB
newtestdb 0.000GB
test 0.000GB
tzl 0.000GB
> use tzl
switched to db tzl
6、删除该数据库
> db.dropDatabase()
{ "dropped" : "tzl", "ok" : 1 }
> show dbs
admin 0.000GB
local 0.000GB
lys 0.000GB
newtestdb 0.000GB
test 0.000GB
> use lll
switched to db lll
> show dbs
admin 0.000GB
local 0.000GB
lys 0.000GB
newtestdb 0.000GB
test 0.000GB
> use student
switched to db student
> use taoche
switched to db taoche
> use student
switched to db student
> gb
2019-09-04T14:23:14.076+0800 E QUERY [thread1] ReferenceError: gb is not defined :
@(shell):1:1
7、db显示在哪个数据库
> db
student
> db.lys.insert({'name:'liyisong'})
2019-09-04T14:24:14.901+0800 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:22
> db.lys.insert({'name:'liyisong'})
2019-09-04T14:24:55.152+0800 E QUERY [thread1] SyntaxError: missing : after property id @(shell):1:22
> use student
switched to db student
> db.lys.insert({'name':'liyisong'})
WriteResult({ "nInserted" : 1 })
8、show collections查询数据表
> show collections
lys
> db.lys.insert({'name':'tzl'})
WriteResult({ "nInserted" : 1 })
> db.lys.insert({'name':'tzl'})
WriteResult({ "nInserted" : 1 })
9、db.数据表.drop()删除该数据表
> db.lys.drop()
true
> show collections
> db.lys.insert({'name':'lys','age':18,'sex':1})
WriteResult({ "nInserted" : 1 })
> db.lys.insert({'name':'wtt','age':18,'sex':1})
WriteResult({ "nInserted" : 1 })
> db.lys.insert({'name':'ljj','age':18,'sex':1})
WriteResult({ "nInserted" : 1 })
> db.lys.insert({'name':'czh','age':18,'sex':1})
WriteResult({ "nInserted" : 1 })
> db.lys.insert({'name':'czh','age':19,'sex':1})
WriteResult({ "nInserted" : 1 })
> db.lys.insert({'name':'wtt','age':17,'sex':1})
WriteResult({ "nInserted" : 1 })
> db.lys.insert({'name':'syj','age':17,'sex':2})
WriteResult({ "nInserted" : 1 })
> db.lys.insert({'name':'dss','age':18,'sex':2})
WriteResult({ "nInserted" : 1 })
10、db.数据表.find()查找该数据表内所有内容
> db.lys.find()
{ "_id" : ObjectId("5d6f5b03ae8dbac5ec948bbb"), "name" : "lys", "age" : 18, "sex" : 1 }
{ "_id" : ObjectId("5d6f5b14ae8dbac5ec948bbc"), "name" : "wtt", "age" : 18, "sex" : 1 }
{ "_id" : ObjectId("5d6f5b1cae8dbac5ec948bbd"), "name" : "ljj", "age" : 18, "sex" : 1 }
{ "_id" : ObjectId("5d6f5b23ae8dbac5ec948bbe"), "name" : "czh", "age" : 18, "sex"