zoukankan      html  css  js  c++  java
  • MongoDB条件查询

    1、查询集合中的所有记录

    db.users.find()
    { "_id" : ObjectId("528b1173613e3289197a6486"), "name" : "lihuai", "age" : 35, "status" : "A", "groups" : [  "news",  "sports" ] }
    { "_id" : ObjectId("528b17ffef83cba2aee5bca9"), "name" : "yekai", "age" : 30, "status" : "A", "groups" : [  "history",  "Math" ] }
    { "_id" : ObjectId("528b187eef83cba2aee5bcaa"), "name" : "lixunhuan", "age" : 40, "status" : "B", "groups" : [  "music",  "Math" ] }

    2、查询集合中的前两条记录

    db.users.find().limit(2)

    3、查询age==30的数据

    db.users.find({age:30})

    4、查询age>35的数据

    db.user.find({age:{$gt:35}})

    5、查询age>=35的数据

    db.user.find({age:{$gte:35}})

    6、<使用$lt,<=使用$lte,!=使用$ne

    7、in的使用

    db.users.find({status:{$in:["A","B"]}})

    8、not in 使用$nin

    db.users.find({status:{$nin:["A"]}})

    9、查出status="A",而且age>30的数据

    db.user.find({status:"A",age:{$gt:30}})

    10、查出status="B"或者age=30的数据

    db.users.find(
        {$or:[
                  {status:"B"},
                  {age:30}
                ]
        }
    )    

    11、查询name以"ye"开头的数据

    db.users.find({name:/^ye/})

    12、查询name以"an"结尾的数据

    db.users.find({name:/an$/})

    13、where的使用,查询出name=="yekai"或者age==35的数据

    db.users.find(
        {$where:function(){
                          return this.name=="yekai" || this.age==35
                       }
        }
    )    
  • 相关阅读:
    x264参数
    用X264编码以后的H264数据
    (转)YUV420存储格式
    YUV数据YUY2到I420
    udp编程中,一次能发送多少个bytes为好?
    (转)c++多态实现的机制
    linux下ping加时间戳实时输出到文件 放后台运行
    如何向AcmeAir注入问题代码
    AcmeAir
    Jmeter压力测试
  • 原文地址:https://www.cnblogs.com/luxh/p/3431761.html
Copyright © 2011-2022 走看看