进入:mongo
windows启动:
服务器启动.\mongod.exe --dbpath "C:\\MongoDB\data\db" --logpath "C:\\MongoDB\data\log\mongo.log"
客户端启动.\mongo.exe --port 27017
不需要创建库、表,可以直接使用
`
show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
use deerlili
db.users.save({name:‘deerlili’})
db.users.save({name:‘lili’,age:18})
db.users.save({name:‘li’,age:18,city:‘cq’})
db.users.save({name:‘li’,age:18,city:‘cq’,tel:‘1333333333’})
db.users.insert({name:‘w’,age:18,city:‘cq’})
save:包括修改和新增
insert:插入
db.users.find()
{ “_id” : ObjectId(“5e626ac1a71729627766f4e5”), “name” : “deerlili” }
db.users.count()
db.users.find().count()
db.users.find({age:18})
db.users.find({age:18}).count()
db.users.find().sort({name:1}) 1:升序
db.users.find().sort({name:-1}) -1:降序
db.users.find().sort({name:-1}).pretty() 美化输出
show dbs
admin 0.000GB
config 0.000GB
deerlili 0.000GB
local 0.000GB
use deerlili
switched to db deerlili
show tables
users
db.stats() :统计数据
{
“db” : “deerlili”,
“collections” : 1,
“views” : 0,
“objects” : 9,
“avgObjSize” : 59.666666666666664,
“dataSize” : 537,
“storageSize” : 36864,
“numExtents” : 0,
“indexes” : 1,
“indexSize” : 36864,
“scaleFactor” : 1,
“fsUsedSize” : 109702520832,
“fsTotalSize” : 126055956480,
“ok” : 1
}
show tables
show collections
users
show users
show logs
global
startupWarnings
show profile
db.system.profile is empty
Use db.setProfilingLevel(2) will enable profiling
Use db.system.profile.find() to show raw profile entries
help
db.help()
db.version()
`
来源:CSDN
作者:鹿粒粒
链接:https://blog.csdn.net/ZXCVBhbase/article/details/104805217