原文出自:http://www.mkyong.com/mongodb/mongodb-import-and-export-example/
返回目录:http://ysj5125094.iteye.com/blog/2192754
MongoDB Import And Export Example
In this tutorial, we show you how to backup and restore MongoDB with the commands : mongoexport
and mongoimport
.
译:在本教程中,我们告诉你如何使用mongoexport和mongoimport命令来备份和恢复MongoDB。
1. Backup database with mongoexport
Few examples to show you how to use the mongoexport
to back up the database.
译:几个例子告诉你如何使用mongoexport备份数据库。
Review some of the common use options.
译:回顾一些常用选项。
$ mongoexport Export MongoDB data to CSV, TSV or JSON files. options: -h [ --host ] arg mongo host to connect to ( <set name>/s1,s2 for -u [ --username ] arg username -p [ --password ] arg password -d [ --db ] arg database to use -c [ --collection ] arg collection to use (some commands) -q [ --query ] arg query filter, as a JSON string -o [ --out ] arg output file; if not specified, stdout is used
1.1 Export all documents (all fields) into the file “domain-bk.json
“.
译:导出全部文档到 “domain-bk.json” 文件。
$ mongoexport -d webmitta -c domain -o domain-bk.json connected to: 127.0.0.1 exported 10951 records
1.2 Export all documents with fields “domain
” and “worth
” only.
译:导出全部文件的 domain 和 worth 字段。
$ mongoexport -d webmitta -c domain -f "domain,worth" -o domain-bk.json connected to: 127.0.0.1 exported 10951 records
1.3 Export all documents with a search query, in this case, only document with “worth > 100000
” will be exported.
译:导出全部 "worth > 100000" 的文档。
$mongoexport -d webmitta -c domain -f "domain,worth" -q '{worth:{$gt:100000}}' -o domain-bk.json connected to: 127.0.0.1 exported 10903 records
1.4 Connect to remote server like mongolab.com, using username and password.
译:使用用户名和密码连接到远程服务器,导出全部文档。
$ mongoexport -h id.mongolab.com:47307 -d heroku_app -c domain -u username123 -p password123 -o domain-bk.json connected to: id.mongolab.com:47307 exported 10951 records
Review the exported file.
译:查看导出的文件。
$ ls -lsa total 2144 0 drwxr-xr-x 5 mkyong staff 170 Apr 10 12:00 . 0 drwxr-xr-x+ 50 mkyong staff 1700 Apr 5 10:55 .. 2128 -rw-r--r-- 1 mkyong staff 1089198 Apr 10 12:15 domain-bk.json
Note
With mongoexport
, all exported documents will be in json format.
译:所有通过 mongoexport 导出的文档,都是JSON格式的。
2. Restore database with mongoimport
Few examples to show you how to use the mongoimport
to restore the database.
译:几个例子,告诉你如何使用mongoimport恢复数据库。
Review some of the common use options.
译:回顾一些常用选项。
$ mongoimport connected to: 127.0.0.1 no collection specified! Import CSV, TSV or JSON data into MongoDB. options: -h [ --host ] arg mongo host to connect to ( <set name>/s1,s2 for sets) -u [ --username ] arg username -p [ --password ] arg password -d [ --db ] arg database to use -c [ --collection ] arg collection to use (some commands) -f [ --fields ] arg comma separated list of field names e.g. -f name,age --file arg file to import from; if not specified stdin is used --drop drop collection first --upsert insert or update objects that already exist
2.1 Imports all documents from file “domain-bk.json
” into database.collection named “webmitta2.domain2″. All non-exists databases or collections will be created automatically.
译:从 “domain-bk.json” 文件导出全部文档到database.collection(webmatta2.domain2)。如果database或collections不存在将自动创建。
$ mongoimport -d webmitta2 -c domain2 --file domain-bk.json connected to: 127.0.0.1 Wed Apr 10 13:26:12 imported 10903 objects
2.2 Imports all documents, insert or update objects that already exist (based on the _id
).
译:导入全部文档,插入或更新已经存在的对象(基于_id)。
$ mongoimport -d webmitta2 -c domain2 --file domain-bk.json --upsert connected to: 127.0.0.1 Wed Apr 10 13:26:12 imported 10903 objects
2.3 Connect to remote server – mongolab.com, using username and password, and import the documents from the local file domain-bk.json
into remote MongoDB server.
译:使用用户名和密码连接到远程服务器,并从文件 "domain-bk.json" 导入到本地文件远程服务器中。
$ mongoimport -h id.mongolab.com:47307 -d heroku_app -c domain -u username123 -p password123 --file domain-bk.json connected to: id.mongolab.com:47307 Wed Apr 10 13:26:12 imported 10903 objects
References
相关推荐
MongoDB导入与导出.pdf 学习资料 复习资料 教学资源
mongoDb导入数据csv 说明文档
找了好久才找到的,还不错!有喜欢的可以下载哦
1.java连接mongo数据库查询统计信息导出为excel表格 2.所有连接参数都可以动态输入,参数包括:ip、端口、数据库名称、集合名称、查询参数(公众号,写在指定文件中),导出表格存放位置
springdata+springmvc+ mongodb很好的例子
MongoDB之Java使用例子,详细的增删改查例子,以及图片保存删除查询等~
几天想着公司要用MongoDB,自然就要用到数据导入导出,就自己学习了一下。本文介绍了mongoDb导入导出数据的方法,有需要的朋友参考下。
MongoDB + MVC 实现上传的例子
MongoDB数据库C#操作例子含源码,实现基本增删改查操作
主要介绍了MongoDB导出查询结果到文件例子,本文直接给出示例代码,简洁易懂,需要的朋友可以参考下
Mongodb 数据库 JAVA 增删改查操作例子
NULL 博文链接:https://ysj5125094.iteye.com/blog/2205022
压缩包包含MongoDB数据库安装包,导入工具安装包、tsv文件导入说明
计算机后端-PHP视频教程. mongodb08 导出导入.wmv
MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。导入导出很管用啊
特征支持量规指标推和推(仅MongoDB> = 3.6支持推) 支持多个MongoDB服务器Golang的公共API 公制缓存支持请注意,这并不是要替代来检测MongoDB内部。 此应用程序根据所需查询(聚合)以prometheus格式导出自定义...
简单的mongodb的使用例子,适合mongodb的入门,和框架搭建
SqlServer数据导入MongoDBSqlServer数据导入MongoDBSqlServer数据导入MongoDB
一个例子,很容易上手的学习代码,有助于对mongodb的了解