mongo 进入数据库,
exit 退出
show dbs 查数据库
db.createCollection(‘stu‘) 创建一个集合,
> use binbin
switched to db binbin
> db.createCollection(‘stu‘)
{ "ok" : 1 }
> show dbs
admin (empty)
binbin 0.078GB
local 0.078GB
在 use binbin 时,是伊娃并进入该数据库,
只有该数据库中有数据时 show dbs 才可以查看到该库,
show collections 查看所有集合,
db.dropDatabaes 删除库 (在哪个库中,就会产出哪个库)
db.stu.drop 删除集合, stu 集合名字
db.stu.insert({name:‘bin‘,age:20}) 插入一条数据
db.stu.insert([{sex:‘boy‘},{addr:‘aaa‘}]) 插入多条数据
> db.stu.insert([{sex:‘boy‘},{addr:‘aaa‘}])
BulkWriteResult({
"writeErrors" : [ ],
"writeConcernErrors" : [ ],
"nInserted" : 2,
"nUpserted" : 0,
"nMatched" : 0,
"nModified" : 0,
"nRemoved" : 0,
"upserted" : [ ]
})
db.stu. find() 查询
id,可以自己定
db.stu. find({name:‘bin‘}) 条件查询
db.stu. find().pretty() 查询
db.stu.update({name:‘bin‘},{xx:‘yy‘}) 全文档更新
潭州课堂25班:Ph201805201 mongo数据 库 第八课 (课堂笔记)
原文:https://www.cnblogs.com/gdwz922/p/9293715.html