mongodb mongodb中比较级查询条件:($lt $lte $gt $gte)(大于、小于)、查找条件

db.getCollection('ctrip_new').find({'metadata.localizations.value':{$eq:'AAAAA'}})

db.getCollection('ctrip_new').find({'total_photo_count':{$gte:7}}).count();

 只显示那个属性,前面是条件,后面是属性,1代表是显示的意思。

db.getCollection('ctrip_new').find({'metadata.localizations.value':'AAAAA'},{'names.name':1})

两个条件查询:

db.getCollection('ctrip').find({$and:[{'overall_rating.star.score':{$gte:2.1,$lt:3}},{'metadata.localizations.value':'AAAAA'}]}).count()

mongodb中比较级查询条件:($lt $lte $gt $gte)(大于、小于)、查找条件

 

查询表中学生年级大于20,如下:

db.getCollection('student').find({'age':{'$gt':'20'}})

$lt    <   (less  than )

$lte    <=  (less than  or equal to )

$gt   >    (greater  than )

$gte   >=    (greater  than or   equal to)

$ne  != (not equal to)不等于  {'age': {'$ne': 20}}

$in  在范围内  {'age': {'$in': [20, 23]}}   注意用list

$nin  (not in)  不在范围内{'age': {'$nin': [20, 23]}} 注意用list

$regex (正则匹配) db.collection.find({'name': {'$regex''^M.*'}})  匹配以M开头的名字

$exists      属性是否存在       {'name': {'$exists': true}}     查找name属性存在

$type     类型判断        {'age': {'$type': 'int'}}       age的类型为int

$text      文本查询      {'$text': {'$search': 'Mike'}}     text类型的属性中包含Mike字符串

$or  查找多种条件   ({'$or':[{'name':'chen'},{'name':'wang'}]})

组合使用方法如下:

db.user.find({"age":{"$gte":18,"$lte":25}})

对于日期的条件查询方法:

db.getCollection('news').find({'pub_date':{'$gte':'2017-07-11  11:0:0'}})

 

查询表中学生年级大于20,如下:

db.getCollection('student').find({'age':{'$gt':'20'}})

$lt    <   (less  than )

$lte    <=  (less than  or equal to )

$gt   >    (greater  than )

$gte   >=    (greater  than or   equal to)

$ne  != (not equal to)不等于  {'age': {'$ne': 20}}

$in  在范围内  {'age': {'$in': [20, 23]}}   注意用list

$nin  (not in)  不在范围内{'age': {'$nin': [20, 23]}} 注意用list

$regex (正则匹配) db.collection.find({'name': {'$regex''^M.*'}})  匹配以M开头的名字

$exists      属性是否存在       {'name': {'$exists': true}}     查找name属性存在

$type     类型判断        {'age': {'$type': 'int'}}       age的类型为int

$text      文本查询      {'$text': {'$search': 'Mike'}}     text类型的属性中包含Mike字符串

$or  查找多种条件   ({'$or':[{'name':'chen'},{'name':'wang'}]})

组合使用方法如下:

db.user.find({"age":{"$gte":18,"$lte":25}})

对于日期的条件查询方法:

db.getCollection('news').find({'pub_date':{'$gte':'2017-07-11  11:0:0'}})

猜你喜欢

转载自www.cnblogs.com/peiminer/p/10218773.html