1.查看集合
show collections
2.向集合中添加数据
db.runoob.insertMany([
{
'title':'data1',
'url':'https://blog.51cto.com/suyanzhu',
'description':'this is data1',
'view':5000
},
{
'title':'data2',
'url':'https://blog.51cto.com/suyanzhu',
'description':'this is data2',
'view':3650
},
{
'title':'data3',
'url':'https://blog.51cto.com/suyanzhu',
'description':'this is data3',
'view':9527
}
])
3.向集合添加数据
db.runoob.insert({
title: 222,
description: 'mongodb',
by: 'suyanzhu',
url: 'https://blog.51cto.com/suyanzhu',
tags: ['php','mongodb'],
likes: 200
})
4.查看所有数据
db.runoob.find().pretty()
5.只返回title键数据
db.runoob.find({},{'title':1,'_id':0}).pretty()
6.只返回结果中2条数据
db.runoob.find({},{'title':1,'_id':0}).pretty().limit(2)
7.limit方法没有参数返回所有数据
db.runoob.find({},{'title':1,'_id':0}).pretty().limit()