// 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的更多相关文章

  1. mongodb collection method

    https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/ db.coll_test.getIndexes()# ...

  2. MongoDB collection Index DB 大小查询

    1.collection中的数据大小 db.collection.dataSize() 2.为collection分配的空间大小,包括未使用的空间db.collection.storageSize() ...

  3. MongoDB的导入导出(7)

    导入/导出可以操作的是本地的mongodb服务器,也可以是远程的. 所以,都有如下通用选项: -h host   主机 --port port    端口 -u username 用户名 -p pas ...

  4. Mongodb数据导出工具mongoexport和导入工具mongoimport介绍

    一.导出工具mongoexport Mongodb中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件.可以通过参数指定导出的数据项,也可以根据指定的条件导 ...

  5. MongoDB 多条件组合查询

    组合条件查询json格式语法 { "$and": [ { "Date": { $gt: ISODate("2015-06-05T00:45:00.00 ...

  6. MongoDB基础之八 备份与恢复

    Mongodb导出与导入 1: 导入/导出可以操作的是本地的mongodb服务器,也可以是远程的.所以,都有如下通用选项:-h host 主机--port port 端口-u username 用户名 ...

  7. MongoDB 及 scrapy 应用

    0 1.Scrapy 使用 MongoDB https://doc.scrapy.org/en/latest/topics/item-pipeline.html#write-items-to-mong ...

  8. Mongodb数据导出工具mongoexport和导入工具mongoimport介绍(转)

    原文地址:http://chenzhou123520.iteye.com/blog/1641319 一.导出工具mongoexport Mongodb中的mongoexport工具可以把一个colle ...

  9. [mongoDB] mongoDb

    mongodb memcached redis        kv数据库(key/value) mongodb 文档数据库,存储的是文档(Bson->json的二进制化). 特点:内部执行引擎为 ...

随机推荐

  1. JSP Servlet学习笔记——使用fileupload上传文件

    关键代码如下: index.jsp <body> <center> <h3>文件上传</h3> <font color="red&quo ...

  2. CRC32 of Ether FCS with STM32

    Everyone knows that STM32F1xx, STM32F2xx, STM32F4xx have a hardware unit with a polynomial CRC32 0x0 ...

  3. Oracle绝对值函数

    1.绝对值:abs() select abs(-2) value from dual; 2.取整函数(大):ceil() select ceil(-2.001) value from dual;(-2 ...

  4. dbMigration .NET 数据同步迁移工具

    官网:http://fishcodelib.com/DBMigration.htm

  5. Asp.net core使用IIS在windows上进行托管

    摘要 最近项目中,尝试使用asp.net core开发,在部署的时候,考虑现有硬件,只能部署在windows上,linux服务器暂时没有. 部署注意事项 代码中启用iis和Kestrel public ...

  6. Snmp学习总结(七)——SNMP4J介绍

    一.SNMP4J介绍 SNMP4J是一个用Java来实现SNMP(简单网络管理协议)协议的开源项目.它支持以命令行的形式进行管理与响应.SNMP4J是纯面向对象设计与SNMP++(用C++实现SNMP ...

  7. NSObject的hash方法

    NSObject的hash方法 说明 本示例仅仅演示一个对象什么时候执行hash方法. 细节 1. 必要的Model类,重载了hash方法用以反映Hash方法是否被调用了 2. 测试 // // Vi ...

  8. 单身毒妈第一至八季/全集Weeds迅雷下载

    本季第一.二.三.四季 Weeds (2005-2008) 看点:由于丈夫的意外身亡,Nancy Botwin成了一名膝下抚有两子的单身母亲,一无所长的她找不到一份能养活一家三口的工作,但天无绝人之路 ...

  9. hex string 换转

    hex2string std::stringstream R; R << std::hex << 0x1254; DWORD Str2Hex(string str){ retu ...

  10. [Android Pro] 组件化:企业级大型项目必经之路

    cp : https://www.csdn.net/article/2011-02-11/291667 摘要:超过一年以上.活跃开发的项目往往到后期陷入了一些共性的问题: 构建速度慢,往往生成一次最终 ...