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的二进制化). 特点:内部执行引擎为 ...
随机推荐
- C#——性能计数器
简要Windows性能监视器: 打开Windows性能监视器的步骤如下: 开始→运行→perfmon→确定 在这里我们可以选择添加我们要监控的计数器,比如:cpu使用率.内存使用量等,作为asp.ne ...
- CRC 详解
http://www.barrgroup.com/Embedded-Systems/How-To/Additive-Checksums CRC Series, Part 1: Additive Che ...
- delphi版本修改PE头源码
//VC++6外衣 1 OEPCODEFIVE: THEAD = ($55, $8B, $EC, $6A, $FF, $68, $00, $00, $00, $00, $68, $00, $00, $ ...
- Java进程线程理解
一个进程包括由操作系统分配的内存空间,包含一个或多个线程.一个线程不能独立的存在,它必须是进程的一部分.一个进程一直运行,直到所有的非守护线程都结束运行后才能结束. 多线程能满足程序员编写高效率的程序 ...
- layoutSubviews 在什么情况下会被触发
layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews 2.addSubview会触发layoutSubviews 3.设置view的Frame会触 ...
- WordPress基础:get_page_link获取页面地址
函数:get_page_link(页面id编号) 作用:获取指定页面的链接地址 用法: $link = get_page_link(2); 输出为:xxx/?page_id=2 如在循环里则不用填写i ...
- SpringMVC方法传递集合数组
背景:实体集合作为参数 数据准备: 1.实体类 class A {private int id; private String name; } 2.集合json字符串 [{"id&quo ...
- linux dig命令 转
dig 命令主要用来从 DNS 域名服务器查询主机地址信息. 查询单个域名的 DNS 信息 dig 命令最典型的用法就是查询单个主机的信息. $ dig baidu.com dig 命令默认的输出信息 ...
- go 用的不多的命令
8.go doc 文档注释相关,可以搭建本地GO文档服务器,包含自己的项目注释,更多细节请参考:https://github.com/hyper-carrot/go_command_tutorial/ ...
- mysql 比较函数和操作符
MYSQL之中的比较函数和操作符: 1.[NOT] BETWEEN ... AND ... Check whether a value is within a range of values 说明: ...