How to duplicate the records in a MongoDB collection
|
// Fill out a literal array of collections you want to duplicate the records in. // Iterate over each collection using the forEach method on the array. // For each collection get (find) all the records and forEach on each of them. // Remove the _id field from each record as MongoDB will generate this for you and // you can't have a duplicate. // Save the record. // This assumes that the collection does not have any unique keys set on any of the // other fields. // Run this in the MongoDB shell
[db.<collection1>, db.<collection2>].forEach(function(collection) { collection.find({}).forEach(function(x) { delete x._id; collection.save(x); }); }); |
From: https://gist.github.com/guyellis/9948194
How to duplicate the records in a MongoDB collection的更多相关文章
- mongodb collection method
https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/ db.coll_test.getIndexes()# ...
- MongoDB collection Index DB 大小查询
1.collection中的数据大小 db.collection.dataSize() 2.为collection分配的空间大小,包括未使用的空间db.collection.storageSize() ...
- MongoDB的导入导出(7)
导入/导出可以操作的是本地的mongodb服务器,也可以是远程的. 所以,都有如下通用选项: -h host 主机 --port port 端口 -u username 用户名 -p pas ...
- Mongodb数据导出工具mongoexport和导入工具mongoimport介绍
一.导出工具mongoexport Mongodb中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件.可以通过参数指定导出的数据项,也可以根据指定的条件导 ...
- MongoDB 多条件组合查询
组合条件查询json格式语法 { "$and": [ { "Date": { $gt: ISODate("2015-06-05T00:45:00.00 ...
- MongoDB基础之八 备份与恢复
Mongodb导出与导入 1: 导入/导出可以操作的是本地的mongodb服务器,也可以是远程的.所以,都有如下通用选项:-h host 主机--port port 端口-u username 用户名 ...
- MongoDB 及 scrapy 应用
0 1.Scrapy 使用 MongoDB https://doc.scrapy.org/en/latest/topics/item-pipeline.html#write-items-to-mong ...
- Mongodb数据导出工具mongoexport和导入工具mongoimport介绍(转)
原文地址:http://chenzhou123520.iteye.com/blog/1641319 一.导出工具mongoexport Mongodb中的mongoexport工具可以把一个colle ...
- [mongoDB] mongoDb
mongodb memcached redis kv数据库(key/value) mongodb 文档数据库,存储的是文档(Bson->json的二进制化). 特点:内部执行引擎为 ...
随机推荐
- 【精选】Jupyter Notebooks里的TensorFlow图可视化
[精选]Jupyter Notebooks里的TensorFlow图可视化 https://mp.weixin.qq.com/s?src=11×tamp=1503060682&a ...
- POJ 2337 Catenyms (有向图欧拉路径,求字典序最小的解)
Catenyms Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8756 Accepted: 2306 Descript ...
- Serial Wire Viewer (SWV)
Being able to display values for counters, sensors and other debugging information is an important p ...
- How to convert a byte to its binary string representation
How to convert a byte to its binary string representation For example, the bits in a byte B are 1000 ...
- Unity3D实践系列09, 物理引擎与碰撞检测
在Unity3D中,一个物体通常包含一个Collider和一个Rigidbody.Collider是碰撞体,一个物体是Collider,才可以进行碰撞检测.Collider组件中的"Is T ...
- Image控件Stretch属性
通过设置Image控件Stretch属性的值可以控制图片的显示形式: 包含的值:None.Fill.Uniform.UniformToFill <Grid x:Name="Layout ...
- Ubuntu 14.04 用户如何安装 VLC 2.2.0
http://www.linuxidc.com/Linux/2014-03/98913.htm http://www.videolan.org/vlc/#download VLC 是一款自由开源.跨平 ...
- javascript游戏引擎
基于JavaScript开发的游戏是唯一一个能够跨桌面,Web和移动三种平台的.今天,本文向大家推荐一些非常棒的JavaScript游戏开发框架. AD:干货来了,不要等!WOT2015 北京站演讲P ...
- HttpMessageNotWritableException: Could not write JSON: No serializer found for class ****
今天碰到一个异常,下面是错误信息 org.springframework.http.converter.HttpMessageNotWritableException: Could not write ...
- 关闭Windows Server 2012的IE增强安全配置
在Windows Server 2012中,IE的安全性被增强,对于没有加入信任站点的网址会弹出提示框: 微软这样做是为了增强IE的安全性,但是在实际的使用过程中并不是很方便.如果是个人电脑安装了Wi ...