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.多条件AND查询
db.runoob.find({'title':'data1','view':5000}).pretty()
5.多条件OR查询
db.runoob.find({$or:[{'title':'data1'},{'view':{$gt:5000}}]}).pretty()
6.同时使用and和or的查询
db.runoob.find({'view':{$gt:3000},$or:[{'title':'data1'},{'description':'this is data2'}]}).pretty()