博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mongodb数据的导出和导入
阅读量:5795 次
发布时间:2019-06-18

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

mongo导出表说明:

root@827995de7c7f:/# mongoexport --helpUsage:  mongoexport 
Export data from MongoDB in CSV or JSON format.See http://docs.mongodb.org/manual/reference/program/mongoexport/ for more information.general options: --help print usage --version print the tool version and exitverbosity options: -v, --verbose=
more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value, e.g. --verbose=N) --quiet hide all log outputconnection options: -h, --host=
mongodb host to connect to (setname/host1,host2 for replica sets) --port=
server port (can also use --host hostname:port)ssl options: --ssl connect to a mongod or mongos that has ssl enabled --sslCAFile=
the .pem file containing the root certificate chain from the certificate authority --sslPEMKeyFile=
the .pem file containing the certificate and key --sslPEMKeyPassword=
the password to decrypt the sslPEMKeyFile, if necessary --sslCRLFile=
the .pem file containing the certificate revocation list --sslAllowInvalidCertificates bypass the validation for server certificates --sslAllowInvalidHostnames bypass the validation for server name --sslFIPSMode use FIPS mode of the installed openssl libraryauthentication options: -u, --username=
username for authentication -p, --password=
password for authentication --authenticationDatabase=
database that holds the user's credentials --authenticationMechanism=
authentication mechanism to usenamespace options: -d, --db=
database to use -c, --collection=
collection to useoutput options: -f, --fields=
[,
]* comma separated list of field names (required for exporting CSV) e.g. -f "name,age" --fieldFile=
file with field names - 1 per line --type=
the output format, either json or csv (defaults to 'json') (default: json) -o, --out=
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 linequerying options: -q, --query=
query filter, as a JSON string, e.g., '{x:{$gt:1}}' --queryFile=
path to a file containing a query filter (JSON) -k, --slaveOk allow secondary reads if available (default true) (default: false) --readPreference=
|
specify either a preference name or a preference json object --forceTableScan force a table scan (do not use $snapshot) --skip=
number of documents to skip --limit=
limit the number of documents to export --sort=
sort order, as a JSON string, e.g. '{x:1}' --assertExists if specified, export fails if the collection does not exist (default: false)

几个常见的说明:

-d :数据库名-c :表名-o :输出的文件名--type : 输出的格式,默认为json-f :输出的字段,如果-type为csv,则需要加上-f "字段名"-q:过滤条件,json字符串

举个栗子:

mongoexport -d dbname -c tablename -o filename.csv --type csv -f "column1,column2” -q '{ filtercolumn :{$gte:1,$lte:100}}' 

 mongo导出库说明:

root@827995de7c7f:/# mongodump --helpUsage:  mongodump 
Export the content of a running server into .bson files.Specify a database with -d and a collection with -c to only dump that database or collection.See http://docs.mongodb.org/manual/reference/program/mongodump/ for more information.general options: --help print usage --version print the tool version and exitverbosity options: -v, --verbose=
more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value, e.g. --verbose=N) --quiet hide all log outputconnection options: -h, --host=
mongodb host to connect to (setname/host1,host2 for replica sets) --port=
server port (can also use --host hostname:port)ssl options: --ssl connect to a mongod or mongos that has ssl enabled --sslCAFile=
the .pem file containing the root certificate chain from the certificate authority --sslPEMKeyFile=
the .pem file containing the certificate and key --sslPEMKeyPassword=
the password to decrypt the sslPEMKeyFile, if necessary --sslCRLFile=
the .pem file containing the certificate revocation list --sslAllowInvalidCertificates bypass the validation for server certificates --sslAllowInvalidHostnames bypass the validation for server name --sslFIPSMode use FIPS mode of the installed openssl libraryauthentication options: -u, --username=
username for authentication -p, --password=
password for authentication --authenticationDatabase=
database that holds the user's credentials --authenticationMechanism=
authentication mechanism to usenamespace options: -d, --db=
database to use -c, --collection=
collection to usequery options: -q, --query= query filter, as a JSON string, e.g., '{x:{$gt:1}}' --queryFile= path to a file containing a query filter (JSON) --readPreference=
|
specify either a preference name or a preference json object --forceTableScan force a table scanoutput options: -o, --out=
output directory, or '-' for stdout (defaults to 'dump') --gzip compress archive our collection output with Gzip --repair try to recover documents from damaged data files (not supported by all storage engines) --oplog use oplog for taking a point-in-time snapshot --archive=
dump as an archive to the specified path. If flag is specified without a value, archive is written to stdout --dumpDbUsersAndRoles dump user and role definitions for the specified database --excludeCollection=
collection to exclude from the dump (may be specified multiple times to exclude additional collections) --excludeCollectionsWithPrefix=
exclude all collections from the dump that have the given prefix (may be specified multiple times to exclude additional prefixes) -j, --numParallelCollections= number of collections to dump in parallel (4 by default) (default: 4) --viewsAsCollections dump views as normal collections with their produced data, omitting standard collections

举个栗子:

mongodump -h 127.0.0.1 -d databasename -o dir

mongo导入库说明:

root@827995de7c7f:/# mongorestore --helpUsage:  mongorestore 
Restore backups generated with mongodump to a running server.Specify a database with -d to restore a single database from the target directory,or use -d and -c to restore a single collection from a single .bson file.See http://docs.mongodb.org/manual/reference/program/mongorestore/ for more information.general options: --help print usage --version print the tool version and exitverbosity options: -v, --verbose=
more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value, e.g. --verbose=N) --quiet hide all log outputconnection options: -h, --host=
mongodb host to connect to (setname/host1,host2 for replica sets) --port=
server port (can also use --host hostname:port)ssl options: --ssl connect to a mongod or mongos that has ssl enabled --sslCAFile=
the .pem file containing the root certificate chain from the certificate authority --sslPEMKeyFile=
the .pem file containing the certificate and key --sslPEMKeyPassword=
the password to decrypt the sslPEMKeyFile, if necessary --sslCRLFile=
the .pem file containing the certificate revocation list --sslAllowInvalidCertificates bypass the validation for server certificates --sslAllowInvalidHostnames bypass the validation for server name --sslFIPSMode use FIPS mode of the installed openssl libraryauthentication options: -u, --username=
username for authentication -p, --password=
password for authentication --authenticationDatabase=
database that holds the user's credentials --authenticationMechanism=
authentication mechanism to usenamespace options: -d, --db=
database to use when restoring from a BSON file -c, --collection=
collection to use when restoring from a BSON file --excludeCollection=
DEPRECATED; collection to skip over during restore (may be specified multiple times to exclude additional collections) --excludeCollectionsWithPrefix=
DEPRECATED; collections to skip over during restore that have the given prefix (may be specified multiple times to exclude additional prefixes) --nsExclude=
exclude matching namespaces --nsInclude=
include matching namespaces --nsFrom=
rename matching namespaces, must have matching nsTo --nsTo=
rename matched namespaces, must have matching nsFrominput options: --objcheck validate all objects before inserting --oplogReplay replay oplog for point-in-time restore --oplogLimit=
[:ordinal] only include oplog entries before the provided Timestamp --oplogFile=
oplog file to use for replay of oplog --archive=
restore dump from the specified archive file. If flag is specified without a value, archive is read from stdin --restoreDbUsersAndRoles restore user and role definitions for the given database --dir=
input directory, use '-' for stdin --gzip decompress gzipped inputrestore options: --drop drop each collection before import --dryRun view summary without importing anything. recommended with verbosity --writeConcern=
write concern options e.g. --writeConcern majority, --writeConcern '{w: 3, wtimeout: 500, fsync: true, j: true}' (defaults to 'majority') (default: majority) --noIndexRestore don't restore indexes --noOptionsRestore don't restore collection options --keepIndexVersion don't update index version --maintainInsertionOrder preserve order of documents during restoration -j, --numParallelCollections= number of collections to restore in parallel (4 by default) (default: 4) --numInsertionWorkersPerCollection= number of insert operations to run concurrently per collection (1 by default) (default: 1) --stopOnError stop restoring if an error is encountered on insert (off by default) --bypassDocumentValidation bypass document validation

举个栗子:

mongorestore -h 127.0.0.1 -d databasename dir

 

转载于:https://www.cnblogs.com/zqyx/p/10174841.html

你可能感兴趣的文章
如何测试ASP.NET Core Web API
查看>>
《The Age of Surge》作者访谈
查看>>
测试人员的GitHub
查看>>
Spring Web Services 3.0.4.RELEASE和2.4.3.RELEASE发布
查看>>
有关GitHub仓库分支的几个问题
查看>>
无服务器计算的黑暗面:程序移植没那么容易
查看>>
云原生的浪潮下,为什么运维人员适合学习Go语言?
查看>>
Webpack入门教程三十
查看>>
EAServer 6.1 .NET Client Support
查看>>
锐捷交换机密码恢复(1)
查看>>
Kali linux virtualbox rc=1908 错误解决办法
查看>>
Erlang学习总结之Erlang语法中的逗号(,)、分号(;),句号(.)的正确用法...
查看>>
linux软件包管理之三(源代码安装)
查看>>
数据库三范式是什么?
查看>>
[转载]设置Ubuntu自动连接无线,无须再输入密钥环和无线密码
查看>>
九叔Xen App测试报告
查看>>
Apache配置
查看>>
Ext gridPanel 单元格数据的渲染
查看>>
Android SDK 的下载代理
查看>>
Method Swizzling对Method的要求
查看>>