美文网首页
【mongodb】update指定行数

【mongodb】update指定行数

作者: Joey_GZ | 来源:发表于2019-11-15 10:36 被阅读0次
  1. 查询
db.push_record.find({"source":"定时推送"});
  1. 更新符合条件的全部记录
db.push_record.update
({"source": "定时推送"}, 
 {$set: {startTime: NumberLong("1573232400000"),
                            time: NumberLong("1573232400000")}},
   false,  -- 默认是false,不插入查询不到的记录;true为插入
   true    -- 默认是false,只更新第一条记录;true则更新全部记录
);
  1. 更新指定数量的记录(配合find()、limit())
db.push_record.find({"source":"定时推送"}).limit(5).forEach(function(a)
db.push_record.update
  ({_id:a._id}, 
   {$set: {startTime: NumberLong("1573318800000"),
           time: NumberLong("1573318800000")}},
   false, 
   true 
   )
);

相关文章

网友评论

      本文标题:【mongodb】update指定行数

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