• 常用mongo语句


    1、根据objectId类型字段checkId并根据_id倒排序查询

    db.xxx.find({"checkId" : ObjectId("5f1ff24a82d5dd3d54b4e82d")}).sort({_id:-1}).limit(20);

    db.xxx.find({addTime:{"$gt":1596279600, "$lte":1596366000},typeId:1,isRegister:1}).limit(20);

    2、查询数量

    db.xxx.find().count();

    db.xxx.find({addTime:{"$gt":1596279600, "$lte":1596366000},typeId:1,isRegister:1}).count();

    3、新增字段

    update命令

    update命令格式:

    db.collection.update(criteria,objNew,upsert,multi)

    参数说明:

    criteria:查询条件

    objNew:update对象和一些更新操作符

    upsert:如果不存在update的记录,是否插入objNew这个新的文档,true为插入,默认为false,不插入。

    multi:默认是false,只更新找到的第一条记录。如果为true,把按条件查询出来的记录全部更新。

    4、添加索引

    db.xxx.createIndex({strategy:1},{name:"IX_strategy"});

    5、批量更新

    方法一:db.xxx.update( { "risk_result" : 10} , { $set : { "strategy" : "30000"} },false,true );

    方法二:

    db.getCollection('xxx').find({"risk_result":10}).forEach(
    function(item){
    db.getCollection('xxx').update({"_id":item._id},{$set:{"strategy": 30000}})
    }
    );

  • 相关阅读:
    前端入门21-JavaScript的ES6新特性
    redis 数据库安装和基本使用
    django 与 Vue 的结合使用说明
    websocket 与 tornado 的结合
    tornado 模板引擎
    tornado 初解
    ajax post 提交数据和文件
    Session Cookies随笔
    爬虫 scrapy 笔记
    绘制验证码 刷新验证码
  • 原文地址:https://www.cnblogs.com/wzk-0000/p/14070034.html
Copyright © 2020-2023  润新知