Mongo导出、导入
1.mongodb 数据导出:
connection options:
/h, /host:<hostname> mongodb host to connect to (setname/host1,host2 for replica sets)
/port:<port> server port (can also use --host hostname:port) authentication options:
/u, /username:<username> username for authentication
/p, /password:<password> password for authentication
/authenticationDatabase:<database-name> database that holds the user's credentials
/authenticationMechanism:<mechanism> authentication mechanism to use namespace options:
/d, /db:<database-name> database to use
/c, /collection:<collection-name> collection to use uri options:
/uri:mongodb-uri mongodb uri connection string output options:
/f, /fields:<field>[,<field>]* comma separated list of field names (required for exporting CSV) e.g. -f "name,age"
/fieldFile:<filename> file with field names - 1 per line
/type:<type> the output format, either json or csv (defaults to 'json') (default: json)
/o, /out:<filename> output file; if not specified, stdout is used
/jsonArray output to a JSON array rather than one object per line
/pretty output JSON formatted to be human-readable
/noHeaderLine export CSV data without a list of field names at the first line querying options:
/q, /query:<json> query filter, as a JSON string, e.g., '{x:{$gt:1}}'
/queryFile:<filename> path to a file containing a query filter (JSON)
/k, /slaveOk allow secondary reads if available (default true) (default: false)
/readPreference:<string>|<json> specify either a preference name or a preference json object
/forceTableScan force a table scan (do not use $snapshot)
/skip:<count> number of documents to skip
/limit:<count> limit the number of documents to export
/sort:<json> sort order, as a JSON string, e.g. '{x:1}'
/assertExists if specified, export fails if the collection does not exist(default: false)
2.mongodb数据导入:
connection options:
/h, /host:<hostname> mongodb host to connect to
(setname/host1,host2 for
replica sets)
/port:<port> server port (can also use
--host hostname:port)
authentication options:
/u, /username:<username> username for authentication
/p, /password:<password> password for authentication
/authenticationDatabase:<database-name> database that holds the
user's credentials
/authenticationMechanism:<mechanism> authentication mechanism to
use namespace options:
/d, /db:<database-name> database to use
/c, /collection:<collection-name> collection to use uri options:
/uri:mongodb-uri mongodb uri connection string input options:
/f, /fields:<field>[,<field>]* comma separated list of
fields, e.g. -f name,age
/fieldFile:<filename> file with field names - 1 per
line
/file:<filename> file to import from; if not
specified, stdin is used
/headerline use first line in input
source as the field list (CSV
and TSV only)
/jsonArray treat input source as a JSON
array
/parseGrace:<grace> controls behavior when type
coercion fails - one of:
autoCast, skipField, skipRow,
stop (defaults to 'stop')
(default: stop)
/type:<type> input format to import: json,
csv, or tsv (defaults to
'json') (default: json)
/columnsHaveTypes indicated that the field list
(from --fields, --fieldsFile,
or --headerline) specifies
types; They must be in the
form of
'<colName>.<type>(<arg>)'.
The type can be one of: auto,
binary, bool, date, date_go,
date_ms, date_oracle, double,
int32, int64, string. For
each of the date types, the
argument is a datetime layout
string. For the binary type,
the argument can be one of:
base32, base64, hex. All
other types take an empty
argument. Only valid for CSV
and TSV imports. e.g.
zipcode.string(),
thumbnail.binary(base64) ingest options:
/drop drop collection before
inserting documents
/ignoreBlanks ignore fields with empty
values in CSV and TSV
/maintainInsertionOrder insert documents in the order
of their appearance in the
input source
/j, /numInsertionWorkers:<number> number of insert operations
to run concurrently (defaults
to 1) (default: 1)
/stopOnError stop importing at first
insert/upsert error
/mode:[insert|upsert|merge] insert: insert only. upsert:
insert or replace existing
documents. merge: insert or
modify existing documents.
defaults to insert
/upsertFields:<field>[,<field>]* comma-separated fields for
the query part when --mode is
set to upsert or merge
/writeConcern:<write-concern-specifier> write concern options e.g.
--writeConcern majority,
--writeConcern '{w: 3,
wtimeout: 500, fsync: true,
j: true}'
/bypassDocumentValidation bypass document validation
示例:
mongoexport.exe -h 127.0.0.1 -u admin -p xxx -d test -c user -o user.json --type=json
mongoimport.exe -h 127.0.0.1 -u admin -p xxx -d test_bak -c user --file=dm_task.json --type=json
示例:
mongoexport.exe -h 127.0.0.1 -u admin -p xxx -d test -c user -o user.csv --type=csv --fields="_id,username,birthday,gender,email,phone"
mongoimport.exe -h 127.0.0.1 -u admin -p xxx -d test -c user_bak --file=user.csv --type=csv --headerline
mongoexport 在不指定输出的情况下输出到stdout,mongoimport不指定输入的情况下从stdin读入数据;所以可以配套使用而不需要本地转储;
示例:
mongoexport.exe -h 127.0.0.1 -u admin -p xxx -d test -c user | mongoimport.exe -h 127.0.0.1 -u admin -p xxx -d test_bak -c user
注意:在数据这个过程中可能会出现因为数据量太大导致连接超时拒绝连接;需要记住数据的位置;然后再第二次导入的时候使用skip跳过已经导过的数据;
示例:
mongoexport.exe -h 127.0.0.1 -u admin -p xxx -d test -c user --skip=234567|mongoimport.exe -h 127.0.0.1 -u admin -p xxx -d test_bak -c user
TIPS:本机性能较好,较空闲的话,可以多开几个线程进行数据操作使用-j 参数;
示例:
mongoexport.exe -h 127.0.0.1 -u admin -p xxx -d test -c user --skip=234567|mongoimport.exe -h 127.0.0.1 -u admin -p xxx -d test_bak -c user -j 4
Mongo导出、导入的更多相关文章
- mongo导出导入
导出例子: mongoexport -d test -c test -q '{sn:1}' -o test.dat 导入例子: mongoimport -d test -c students stud ...
- MongoDB学习笔记(三)--权限 && 导出导入备份恢复 && fsync和锁
权限 绑定内网I ...
- mongodb表索引备份,索引的导出导入
背景 发现有两个mongodb环境的数据库表索引不一致,另一个数据库有索引缺失,需要将一个数据库里的所有表索引导入到另一个数据库 也可用于单独备份数据库所有表的索引 写mongo shell的js脚本 ...
- Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(上)
<Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(上)> <Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(下)> 目的:指导项 ...
- Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(下)
<Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(上)> <Oracle简单常用的数据泵导出导入(expdp/impdp)命令举例(下)> 目的:指导项 ...
- oracel数据导出导入
一.导出模式(三种模式)及命令格式 1. 全库模式 exp 用户名/密码@网络服务名 full=y file=路径\文件名.dmp log=路径\文件名.log 2. 用户模式(一般情况下采用此模式) ...
- SQL SERVER几种数据迁移/导出导入的实践
SQLServer提供了多种数据导出导入的工具和方法,在此,分享我实践的经验(只涉及数据库与Excel.数据库与文本文件.数据库与数据库之间的导出导入). (一)数据库与Excel 方法1: 使用数据 ...
- BCP导出导入大容量数据实践
前言 SQL SERVER提供多种不同的数据导出导入的工具,也可以编写SQL脚本,使用存储过程,生成所需的数据文件,甚至可以生成包含SQL语句和数据的脚本文件.各有优缺点,以适用不同的需求.下面介绍大 ...
- [CMD]oracle数据库的导出导入
除了推荐使用PL/SQL Developer 工具对oracle进行导出导入(http://www.cnblogs.com/whylaughing/p/5983490.html )之外,比较常用的还有 ...
- [PL/SQL]oracle数据库的导出导入
一.PL/SQL Developer工具一般对oracle的导入导出有以下4中方式: 1.Oracle导出导入方式 这种方式导出导入为.dmp的文件格式,.dmp文件是二进制的,可以跨平台,还能包含权 ...
随机推荐
- APPScan安全测试工具
1.下载IBM Security AppScan Standard.rar免费版,下载地址:https://www.cr173.com/soft/820147.html,安装完成后,配置扫描配置提示无 ...
- struts2的作用是什么
struts2是一种重量级的框架,位于MVC架构中的controller,可以分析出来,它是用于接受页面信息然后通过内部处理,将结果返回. 同时struts2也是一个web层的MVC框架,那么什么是s ...
- CPU缓存
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11520840.html 由于CPU发展的速度远快于内存的发展,CPU的处理速度就比内存的访问速度快得多 ...
- Vue.js----更换头像不实时更新问题
原因 导致问题的原因是缓存造成的,因为你图片变了但是读取头像的地址还会没有变化的 解决思路 所以解决的思路就是上传之后让图片地址改变,那么我们就可以在上传的时候给地址加上一个时间戳那么久可一达到目的了 ...
- centos6安装完成之后必要的配置
centos6安装完成之后必要的配置 一配置yum源 [root@centos61 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirro ...
- PHP之面向对象小结
PHP 中创建对象 类创建后,我们可以使用 new 运算符来实例化该类的对象: $runoob = new Site; PHP 构造函数 构造函数 ,是一种特殊的方法.主要用来在创建对象时初始化对象, ...
- [CSP-S模拟测试]:u(差分)
题目背景 $\frac{1}{4}$遇到了一道水题,完全不会做,于是去请教小$D$.小$D$看了一眼就切掉了这题,嘲讽了$\frac{1}{4}$一番就离开了.于是,$\frac{1}{4}$只好来问 ...
- ValueError: invalid literal for int() with base 10问题处理
问题描述: 在用pthon写脚本得过程中,发生错误,ValueError: invalid literal for int() with base 10,这种错误是值得类型转换错误,int()函数是可 ...
- 6105 - deauth after EAPOL key exchange sequence
wifi无法连接公司的网络 Warning Error in Event Log - deauth after EAPOL key exchange sequence https://forums.i ...
- identityserver4踩坑总结
1.在配置id4服务端的时候要注意client里面的 AllowedScopes开放的值要和GetIdentityResources中加入的值是一样的,不然调用以后报{"error" ...