美文网首页
MongoDB 更新字段操作

MongoDB 更新字段操作

作者: 非典型程序员 | 来源:发表于2017-06-29 14:11 被阅读681次

    更新字段类型和字段值

    db.getCollection('book').find({}).forEach(
        function(X){
            x.age = new NumberInt(x.age);// 将字符串转化为数字
            db.book.save(x);//保存数据
    });
    

    添加字段或更新值

    db.getCollection('test').update(
      {},
      {
           $set:{
                 'createTime':'2017-06-29 08:08',
                 'updateTime':'2017-06-29 08:08
           }
      }
    );
    

    相关文章

      网友评论

          本文标题:MongoDB 更新字段操作

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