博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongodb命令----批量更改文档字段名
阅读量:5241 次
发布时间:2019-06-14

本文共 2017 字,大约阅读时间需要 6 分钟。

因为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":"\u8bfa\u57fa\u4e9a5320 XpressMusic","goods_number":8,"click_count":13,"shop_price":1311.00,"add_time":1241967762}, {
"goods_id":14,"cat_id":4,"goods_name":"\u8bfa\u57fa\u4e9a5800XM","goods_number":1,"click_count":6,"shop_price":2625.00,"add_time":1241968492}, {
"goods_id":15,"cat_id":3,"goods_name":"\u6469\u6258\u7f57\u62c9A810","goods_number":3,"click_count":8,"shop_price":788.00,"add_time":1241968703}, {
"goods_id":16,"cat_id":2,"goods_name":"\u6052\u57fa\u4f1f\u4e1aG101","goods_number":0,"click_count":3,"shop_price":823.33,"add_time":1241968949}, {
"goods_id":17,"cat_id":3,"goods_name":"\u590f\u65b0N7","goods_number":1,"click_count":2,"shop_price":2300.00,"add_time":1241969394}, {
"goods_id":18,"cat_id":4,"goods_name":"\u590f\u65b0T5","goods_number":1,"click_count":0,"shop_price":2878.00,"add_time":1241969533}, {
"goods_id":19,"cat_id":3,"goods_name":"\u4e09\u661fSGH-F258","goods_number":12,"click_count":7,"shop_price":858.00,"add_time":1241970139}, {
"goods_id":20,"cat_id":3,"goods_name":"\u4e09\u661fBC01","goods_number":12,"click_count":14,"shop_price":280.00,"add_time":1241970417}, {
"goods_id":21,"cat_id":3,"goods_name":"\u91d1\u7acb A30","goods_number":40,"click_count":4,"shop_price":2000.00,"add_time":1241970634}, {
"goods_id":22,"cat_id":3,"goods_name":"\u591a\u666e\u8fbeTouch HD","goods_number":1,"click_count":15,"shop_price":5999.00,"add_time":1241971076} ])

 

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

那么,应该如此操作

db.columnsample.updateMany({},{  "$rename":{
"remponse":"response"}})

 

转载于:https://www.cnblogs.com/saintdingspage/p/9557301.html

你可能感兴趣的文章
Oracle-05
查看>>
linux grep 搜索查找
查看>>
Not enough free disk space on disk '/boot'(转载)
查看>>
android 签名
查看>>
堆 栈
查看>>
Kth Smallest Element in Unsorted Array
查看>>
vue项目中使用百度统计
查看>>
android:scaleType属性
查看>>
SuperEPC
查看>>
RBAC用户角色权限设计方案
查看>>
thymeleaf
查看>>
CentOS7安装iptables防火墙
查看>>
mysql-5.7 innodb 的并行任务调度详解
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
python针对excel的读写操作-----openpyxl
查看>>
最后几本书,不珍藏了。
查看>>
Js时间处理
查看>>
Java项目xml相关配置
查看>>
按钮实现A标签新窗口打开(不用window.open)
查看>>