mongo导出表说明:

root@827995de7c7f:/# mongoexport --help
Usage:
mongoexport <options> 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 exit verbosity options:
-v, --verbose=<level> 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 output 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) ssl options:
--ssl connect to a mongod or mongos that has ssl enabled
--sslCAFile=<filename> the .pem file containing the root certificate chain from the certificate authority
--sslPEMKeyFile=<filename> the .pem file containing the certificate and key
--sslPEMKeyPassword=<password> the password to decrypt the sslPEMKeyFile, if necessary
--sslCRLFile=<filename> 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 library 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 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 - 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)

几个常见的说明:

-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 --help
Usage:
mongodump <options> 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 exit verbosity options:
-v, --verbose=<level> 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 output 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) ssl options:
--ssl connect to a mongod or mongos that has ssl enabled
--sslCAFile=<filename> the .pem file containing the root certificate chain from the certificate authority
--sslPEMKeyFile=<filename> the .pem file containing the certificate and key
--sslPEMKeyPassword=<password> the password to decrypt the sslPEMKeyFile, if necessary
--sslCRLFile=<filename> 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 library 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 query 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=<string>|<json> specify either a preference name or a preference json object
--forceTableScan force a table scan output options:
-o, --out=<directory-path> 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=<file-path> 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-name> collection to exclude from the dump (may be specified multiple times to exclude additional collections)
--excludeCollectionsWithPrefix=<collection-prefix> 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 ( by default) (default: )
--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 --help
Usage:
mongorestore <options> <directory or file to restore> 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 exit verbosity options:
-v, --verbose=<level> 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 output 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) ssl options:
--ssl connect to a mongod or mongos that has ssl enabled
--sslCAFile=<filename> the .pem file containing the root certificate chain from the certificate authority
--sslPEMKeyFile=<filename> the .pem file containing the certificate and key
--sslPEMKeyPassword=<password> the password to decrypt the sslPEMKeyFile, if necessary
--sslCRLFile=<filename> 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 library 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 when restoring from a BSON file
-c, --collection=<collection-name> collection to use when restoring from a BSON file
--excludeCollection=<collection-name> DEPRECATED; collection to skip over during restore (may be specified multiple times to exclude additional collections)
--excludeCollectionsWithPrefix=<collection-prefix> DEPRECATED; collections to skip over during restore that have the given prefix (may be specified multiple times to exclude additional prefixes)
--nsExclude=<namespace-pattern> exclude matching namespaces
--nsInclude=<namespace-pattern> include matching namespaces
--nsFrom=<namespace-pattern> rename matching namespaces, must have matching nsTo
--nsTo=<namespace-pattern> rename matched namespaces, must have matching nsFrom input options:
--objcheck validate all objects before inserting
--oplogReplay replay oplog for point-in-time restore
--oplogLimit=<seconds>[:ordinal] only include oplog entries before the provided Timestamp
--oplogFile=<filename> oplog file to use for replay of oplog
--archive=<filename> 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=<directory-name> input directory, use '-' for stdin
--gzip decompress gzipped input restore options:
--drop drop each collection before import
--dryRun view summary without importing anything. recommended with verbosity
--writeConcern=<write-concern> 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 ( by default) (default: )
--numInsertionWorkersPerCollection= number of insert operations to run concurrently per collection ( by default) (default: )
--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

最新文章

  1. Spark机器学习读书笔记-CH03
  2. cocos2dx 3.x(场景(层)的生命周期)
  3. 【转载】-- vi/vim使用
  4. css 强制换行
  5. Unity3D ShaderLab 创建自定义高光类型
  6. windows和linux中检查端口是否被占用
  7. 将对象保存至文件——CArchive
  8. CDN的全称是Content Delivery Network,即内容分发网络
  9. WPF(MultiTrigger)
  10. 思迅/泰格/科脉/收银软件/商超软件数据库修复解决断电造成损坏的mdb\dat文件SQL数据库 置疑 修复 恢复
  11. 关系型数据库工作原理-数据库查询器(翻译自Coding-Geek文章)
  12. Angular4---认证---使用HttpClient拦截器,解决循环依赖引用的问题
  13. 在容器中运行 Jenkins pipeline 任务
  14. InnoDB基本特性
  15. leetcode 557. Reverse Words in a String III 、151. Reverse Words in a String
  16. 牛客网-2018年全国多校算法寒假训练营练习比赛(第四场)-A
  17. Spring boot+CXF开发WebService Demo
  18. wpf-X名称空间Attribute
  19. webpack 4 知识点
  20. Masonry基本语法

热门文章

  1. java几种基本排序算法
  2. linux第一个C语言和sh脚本
  3. MySQL存储过程和临时表
  4. ansible之基本原理及命令
  5. Vim中增加ga键的vmap功能
  6. yii2.0表单自带验证码
  7. 魅族首页导航效果(不兼容IE)
  8. Django应用的打包和应用的安装和卸载
  9. mybatis查询缓存
  10. [Raspberry]001Ubuntu下查看linux版本,内核版本,系统位数,gcc版本