• mongodb命令---花样查询语句


    闲言少叙

    查出价格低于200的商品信息----包含商品名称,货物编号,价格,添加信息等

    db.goods.find(
    {"shop_price":{$lt:200}},
    {"shop_price":1,"goods_name":1,"goods_id":1,"add_time":1}
    )

     商品分类不为3的商品

    db.goods.find(
    
    {"cat_id":{$ne:3}},
    
    {"shop_price":1,"goods_name":1,"goods_id":1,"cat_id":1}
    
    )

    价格低于或等于400的商品

    db.goods.find(
    {"shop_price":{$lte:400}},
    {"goods_name":1,"goods_id":1,"shop_price":1,"cat_id":1}
    )

     查处价格大于等于100,小于等于500的商品

    db.goods.find(
    {$and:
     [{"shop_price":{$lte:500}},{"shop_price":{$gte:100}}]   
    },
    {"goods_name":1,"goods_id":1,"shop_price":1,"cat_id":1}
    )

    查询不属于栏目3和栏目11的产品用$and

    db.goods.find(
    {$and:
        [{cat_id:{$ne:3}},{cat_id:{$ne:11}}]
    },
    {"goods_name":1,"goods_id":1,"shop_price":1,"cat_id":1}
    )

    查询不属于栏目3和栏目11的产品用$nin

    db.goods.find(
    {"cat_id":{$nin:[3,11]}},
    {"goods_name":1,"goods_id":1,"shop_price":1,"cat_id":1}
    )

    查询不属于栏目3和栏目11的产品用$nor

    db.goods.find(
    {$nor:[{cat_id:3},{cat_id:11}]},
    {"goods_name":1,"goods_id":1,"shop_price":1,"cat_id":1}
    )

    取出大于100小于300的商品或者小于5000,大于4000的商品

    db.goods.find(
    {$or:[
    {$and:[{"shop_price":{$lte:300}},{"shop_price":{$gte:100}},]},
    {$and:[{"shop_price":{$lt:5000}},{"shop_price":{$gt:4000}},]}
    ]},
    {"goods_name":1,"goods_id":1,"shop_price":1,"cat_id":1}
    ) 

    取出商品编号对5求余等于1的记录

    db.goods.find(
    {cat_id:{$mod:[5,1]}},
    {"goods_name":1,"goods_id":1,"shop_price":1,"cat_id":1}
    )

    取出分类为3或11的商品

    db.goods.find(
    {"cat_id":{$in:[3,11]}},
    {
    "goods_name":1,"goods_id":1,"shop_price":1,"cat_id":1}
    )
  • 相关阅读:
    MySQLdb 部署
    python 操作python
    python 面向对象(进阶篇)
    Python 面向对象(初级篇)
    Apache环境下强制http跳转至https的配置总结
    linux Apache设置https访问以及加载mod_ssl.so模块以及问题解决
    使用dd命令快速生成大文件或者小文件的方法
    Let’s Encrypt/Certbot移除/remove/revoke不需要的域名证书
    Vsphere中ESXi主机ssh开启的三种方法
    RackTables在LNMP系统的安装及使用
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/9557556.html
Copyright © 2020-2023  润新知