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.find().pretty()
4.指定返回键(注意,只能全1或全0)
db.runoob.find({'view':{$gt:5000}},{title:1,view:1}).pretty()
5.无查询条件参数
db.runoob.find({},{title:1,view:1}).pretty()
6.不返回_id,url,description键
db.runoob.find({},{_id:0,url:0,description:0}).pretty()
转载于:https://blog.51cto.com/suyanzhu/2307878