db.users.find({},{a:1, b:1})
查询表
Select * from users
db.users.find()
查询表
Select * from users where age=33
db.users.find({age:33})
条件查询
Select a, b from users where age=33
db.users.find({age:33},{a:1, b:1})
条件查询
select * from users where age<33
db.users.find({'age':{$lt:33}})
条件查询
select * from users where age>33 and age<=40
db.users.find({'age':{$gt:33,$lte:40}})
条件查询
select * from users where a=1 and b='q'
db.users.find({a:1,b:'q'})
条件查询
select * from users where a=1 or b=2
db.users.find( { $or : [ { a : 1 } , { b : 2 } ] } )
条件查询
select * from users limit 1
db.users.findOne()
条件查询
select * from users where name like "%Joe%"
db.users.find({name:/Joe/})
模糊查询
select * from users where name like "Joe%"
db.users.find({name:/^Joe/})
db.getCollection('info').find({type:2,"data.issue_type":"SUGGESTIONS","created":{$gt:1467388800,$lt:1469980800}}).count()
db.getCollection('info').distinct("data.issue_type",{type:2})
db.getCollection('detail').find({title: /.*郑爽.*/})
分类:
版权声明:本文为博主原创文章,未经博主允许不得转载。
db.course.find( { "lectures.lectures_count": { $exists: true } } )
查询course表中,存在lectures_count字段的记录信息
删除course表中,所有的lectures.lectures_count字段
db.course.update({},{$unset:{"lectures.lectures_count":""}},{multi:true})
根据条件往表里插入一个字段
db.lecture.update({"course_id":"5352d5ab92fc7705666ae8c9"},{$set:{"file_type":"PDF"}},{multi:true})
在mongo中有一个field是list类型的,那怎么查询哪些文档超过了这个长度呢
方法:db.accommodations.find({'name.1': {$exists: true}})
参见http://stackoverflow.com/questions/7811163/query-for-documents-where-array-size-is-greater-than-1/15224544#15224544mongo中查询count distinct
db.content_simhash_repeat.distinct('url')
db.content_simhash_repeat.distinct('url').length
No comments:
Post a Comment