首页
Javascript
Html
Css
Node.js
Electron
移动开发
小程序
工具类
服务端
浏览器相关
前端收藏
其他
关于
公司注册

mongodb批量操作

2021年12月30日 发布 阅读(1749) 作者:Jerman

操作同一表的数据

批量重命名某些字段

  1. db.getCollection("docs_article").updateMany({},{"$rename":{"modifyAuthor":"updateBy"}});

批量删除某些不需要的字段

  1. db.getCollection("docs_article").updateMany({},{"$unset":{"modifyNickname":""}});

批量修改数据类型

  1. // 如缩略图如字符串改成数组
  2. db.article.find({thumbnail:{$exists:true}}).forEach(function(x) {
  3. x.thumbnail = [x.thumbnail];
  4. db.article.save(x);
  5. })
版权声明:本站文章除特别声明外,均采用署名-非商业性使用-禁止演绎 4.0 国际 许可协议,如需转载,请注明出处