1.查看集合
show collections
2.添加多条数据
db.runoob.insertMany([
{
'title':'MongoDB Overview',
'description':'MongoDB is no sql database',
'by_user':'demo.runoob.com',
'url':'http://www.runoob.com',
'tags':['mongodb', 'database', 'NoSQL'],
'likes':100
},
{
'title':'NoSQL Overview',
'description':'No sql database is very fast',
'by_user':'demo.runoob.com',
'url':'http://www.runoob.com',
'tags':['mongodb', 'database', 'NoSQL'],
'likes':10
},
{
'title':'MongoDB Overview1',
'description':'MongoDB is no sql database',
'by_user':'study.runoob.com',
'url':'http://www.runoob.com',
'tags':['mongodb', 'database', 'NoSQL'],
'likes':100
},
{
'title':'NoSQL Overview1',
'description':'No sql database is very fast',
'by_user':'study.runoob.com',
'url':'http://www.runoob.com',
'tags':['mongodb', 'database', 'NoSQL'],
'likes':10
}
])
3.查看所有数据
db.runoob.find().pretty()
4.分组查询
db.runoob.aggregate([{$group : {_id : "$by_user", num_tutorial : {$sum : 1}}}])
转载于:https://blog.51cto.com/suyanzhu/2308245