mongodb 查询语句
#查询
db.spit.insert({connect:"八维学院",userid:"1001",nickname:"杰农",visits:NumberInt(10000),_id:"4"})
db.spit.insert({connect:"八维学院映晚霞",userid:"1002",nickname:"爱丽丝",visits:NumberInt(20000),_id:"3"})
db.spit.insert({connect:"八维学院英文系",userid:"1003",nickname:"
安杰拉",visits:NumberInt(30000),_id:"2"})
db.spit.insert({connect:"八维学院国贸翻译",userid:"1004",nickname:"扈三娘",visits:NumberInt(40000),_id:"1"})
db.spit.insert({connect:"八维学云计算",userid:"1005",nickname:"孙家",visits:NumberInt(50000),_id:"5"})
db.spit.find()
#精确查询
db.spit.find({userid:"1002"})
#只显示一条
db.spit.findOne({userid:"1001"})
#指定查寻并返回只显示条数
db.spit.find().limit(6)
#修改
db.spit.update({_id:"1"},{$se:{visits:NumberInt(31000)}})
db.spit.find()
#删除来自一的编号
db.spit.remove({_id:"1"});
db.spit.count({userid:"1001"});
db.spit.find({content:/八维学院国贸翻译/})
db.spit.find({content:/^八维学/});
#大于 $gt >
db.spit.find({visits:{$gt:12000}})
#小于 $lt <
db.spit.find({visits:{$lt:12000}})
#大于等于 $gte
db.spit.find({visits:{$gte:12000}})
#小于等于 $lte
db.spit.find({visits:{$lte:12000}})
#包含与不包含 $in $nin
db.spit.find({userid:{$nin:["1001","1002"]}})
#条件关联 $and:[{},{},{}] $or:[{},{},{}]
db.spit.find({$and:[{visits:{$gt:10000}},{visits:{$lt:20000}}]})
#浏览器小于20000或者用户id等于1001
db.spit.find({$or:[{visits:{$lt:20000}},{userid:"1001"}]})
#列值增长 $inc
db.spit.update({_id:"3"},{$inc:{visits:NumberInt(1)}})