美文网首页
mongodb更改集合中的数据类型(将string更改为int类

mongodb更改集合中的数据类型(将string更改为int类

作者: 一位先生_ | 来源:发表于2023-04-26 14:23 被阅读0次

    场景: 我需要将集合中的日期字段date由字符串更改为int整形
    我这里在_id的基础上,指定了id范围
    db.pm_report_facebook_ad_gender_age_test.find().forEach(
    function(doc){
    db.pm_report_facebook_ad_gender_age_test.update({'_id': doc._id, 'id': {'gte':10001075464, 'lte': 10001077832}},{$set:{"date": NumberInt(doc["date"])}}); // 改为整型
    }
    );

    参考:https://www.imooc.com/article/318380

    相关文章

      网友评论

          本文标题:mongodb更改集合中的数据类型(将string更改为int类

          本文链接:https://www.haomeiwen.com/subject/shyvjdtx.html