zoukankan      html  css  js  c++  java
  • mongodb命令----批量更改文档字段名

    因为mongodb基于javascript的特性,为了体验cursor的威力我们不妨利用js的for循环创建记录

    先创建文档

    db.createCollection("columnsample")

    在文档中插入数据

    for(var i = 1;i<10001;i++)
    {
      db.columnsample.insert(
      {
      _id:i,
      name:"陈培昌"+i,
      content:  "陈培昌打了沙袋"+i+"",
      respomse:"嗷儿喂~"
      }
      )
    }

    这里介绍一种批量插入数据的办法,特此鸣谢燕十八的PHP开发课程mongodb章节,这里的数据范例来自相关课件

    其格式为db.collection.insert([{记录1},{记录2},{记录3}])

    db.goods.insert(
    [
    {
    "goods_id":13,"cat_id":3,"goods_name":"u8bfau57fau4e9a5320 XpressMusic","goods_number":8,"click_count":13,"shop_price":1311.00,"add_time":1241967762},
    {"goods_id":14,"cat_id":4,"goods_name":"u8bfau57fau4e9a5800XM","goods_number":1,"click_count":6,"shop_price":2625.00,"add_time":1241968492},
    {"goods_id":15,"cat_id":3,"goods_name":"u6469u6258u7f57u62c9A810","goods_number":3,"click_count":8,"shop_price":788.00,"add_time":1241968703},
    {"goods_id":16,"cat_id":2,"goods_name":"u6052u57fau4f1fu4e1aG101","goods_number":0,"click_count":3,"shop_price":823.33,"add_time":1241968949},
    {"goods_id":17,"cat_id":3,"goods_name":"u590fu65b0N7","goods_number":1,"click_count":2,"shop_price":2300.00,"add_time":1241969394},
    {"goods_id":18,"cat_id":4,"goods_name":"u590fu65b0T5","goods_number":1,"click_count":0,"shop_price":2878.00,"add_time":1241969533},
    {"goods_id":19,"cat_id":3,"goods_name":"u4e09u661fSGH-F258","goods_number":12,"click_count":7,"shop_price":858.00,"add_time":1241970139},
    {"goods_id":20,"cat_id":3,"goods_name":"u4e09u661fBC01","goods_number":12,"click_count":14,"shop_price":280.00,"add_time":1241970417},
    {"goods_id":21,"cat_id":3,"goods_name":"u91d1u7acb A30","goods_number":40,"click_count":4,"shop_price":2000.00,"add_time":1241970634},
    {"goods_id":22,"cat_id":3,"goods_name":"u591au666eu8fbeTouch HD","goods_number":1,"click_count":15,"shop_price":5999.00,"add_time":1241971076}
    ] )

    大功告成!.......oh,shit!字段名根本就拼错了,response应该是!

    那么,应该如此操作

    db.columnsample.updateMany(
    {},
    {
      "$rename":{"remponse":"response"}
    }
    )
  • 相关阅读:
    SQL SERVER 2008的数据压缩
    protected,internal和protected internal
    CSS笔记
    太吓人了!妈妈必看:国内人贩子抢孩子竟使出狠招
    ASP.NET上传图片的简单方法
    VS2005快捷键大全
    判断ExecuteScalar()是否返回结果
    AppSettings和ConnectionStrings的区别
    VSS中的签入和签出
    对目前工作烦躁的人来看看,你真正明白多少
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/9557301.html
Copyright © 2011-2022 走看看