mongodb安装与导入导出指南

1,972次阅读
没有评论

MongoDB 是由 C++++ 语言编写的非关系型数据库,是一个基于分布式文件存储的开源数据库系统,其内容存储形式类似 JSON 对象,它的字段值可以包含其他文档,数组及文档数组,非常灵活。

**安装地址**:https://www.mongodb.com/download-center/community

* 官方网站:[https://www.mongodb.com](https://b3logfile.com/siyuan/1605935194040/https://www.mongodb.com/)
* 官方文档:[https://docs.mongodb.com](https://b3logfile.com/siyuan/1605935194040/https://docs.mongodb.com/)
* GitHub:[https://github.com/mongodb](https://b3logfile.com/siyuan/1605935194040/https://github.com/mongodb)
* 中文教程:[http://www.runoob.com/mongodb/mongodb-tutorial.html](https://b3logfile.com/siyuan/1605935194040/http://www.runoob.com/mongodb/mongodb-tutorial.html)

## 安装与配置

### 安装

– 安装 MongoDB(不推荐安装到 C 盘,如果不能安装到其他盘,就将 mongo 文件夹剪贴到其他盘)
– 进入安装目录(我的是 `D:mongo`)下,有个 bin 文件夹,里面有 exe 可执行文件
– 建立数据文件夹 `D:mogodatadata`,用来存储数据和 MongoDB 的配置
– 接着进入 cmd,输入 `CD D:mongobin`,转到该目录(目录地址以安装路径为准),接着输入 `mongod –dbpath D:mogodatadata`(目录同样以设置的为准),就会启动 MongoDB。会输出几十行带有时间的信息,最后一行显示 `waiting for connections on port 27017`,表明 MongoDB 服务器已经启动,正在 27017 窗口等待连接。

### 配置成服务

– 在数据文件夹 `D:mongodatadata` 下新建文件夹 `log`,进入该文件夹新建 `mongo.log`,即:`D:mogodatadatalogmongo.log`,
– 启动管理员模式的 cmd
– 输入 `D: `,转到 D 盘路径
– 输入 `CD D:mongobin`
– 输入 `mongod –dbpath “D:mongodatadata” –logpath “D:mogodatadatalogmongo.log” –serviceName “mongodb” –serviceDisplayName “mongodb” –install`(两个路径分别是数据根目录和 log 完整地址)
– `win+r` 进入“运行”界面,输入 `services.msc` 进入”服务”,查看 mongo 服务项,并将其启动(另一种启动服务方式是:以管理员身份启动 cmd,在 cmd 中输入 `net start MongoDB`,然后出现 MongoDB 服务启动成功 字样说明我们启动该服务成功!)
– 接着把 MongoDB 的 bin 文件地址配置到 path 环境变量中,就可以直接用 cmd 打开 MongoDB 了(输入 mongo 即可)

[参考资料](https://b3logfile.com/siyuan/1605935194040/https://www.cnblogs.com/tim100/p/6721415.html)

在这里推荐一个可视化工具 RoboMongo/Robo 3T,使用简单,功能强大,官方网站:[https://robomongo.org/](https://b3logfile.com/siyuan/1605935194040/https://robomongo.org/),三大平台都有支持,下载链接:[https://robomongo.org/download](https://b3logfile.com/siyuan/1605935194040/https://robomongo.org/download)。

![image.png](https://www.sitstars.com/usr/uploads/2021/06/39495323.png)

删除服务命令:在 `bin` 目录下执行 `mongod.exe –remove –serviceName “MongoDB”`

## 导入导出

注意:直接在 CMD 中运行即可,不必进入 mongo 中操作。

导出 JSON

“`mongodb
语法:mongoexport -d dbname -c collectionname -o file –type json/csv -f field
参数说明:
-d :数据库名
-c :collection名
-o :输出的文件名
–type : 输出的格式,默认为json
-f :输出的字段,如果-type为csv,则需要加上-f “字段名”
示例:
mongoexport -d mdpicture -c acg -o D:mogodataexportacg.json
mongoexport -d mdpicture -c hash_url -o D:mogodataexporthash_url.json
“`

导入 JSON

“`mongodb
语法:mongoimport -d dbname -c collectionname –file filename –headerline –type json/csv -f field
参数说明:
-d :数据库名
-c :collection名
–type :导入的格式默认json
-f :导入的字段名
–headerline :如果导入的格式是csv,则可以使用第一行的标题作为导入的字段
–file :要导入的文件
示例:
mongoimport -d mdpicture -c hash_url –file D:mogodataexporthash_url.json
mongoimport -d mdpicture -c acg –file D:mogodataexportacg.json
“`Read More 

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2023 年 3 月
 12345
6789101112
13141516171819
20212223242526
2728293031  
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026 Jay 2025-12-22 09...
面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25

面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25

面向「空天具身智能」,北航团队提出星座规划新基准丨NeurIPS’25 鹭羽 2025-12-13 22:37...
钉钉又发新版本!把 AI 搬进每一次对话和会议

钉钉又发新版本!把 AI 搬进每一次对话和会议

钉钉又发新版本!把 AI 搬进每一次对话和会议 梦晨 2025-12-11 15:33:51 来源:量子位 A...
商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1

商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1

商汤Seko2.0重磅发布,合作短剧登顶抖音AI短剧榜No.1 十三 2025-12-15 14:13:14 ...
跳过“逐字生成”!蚂蚁集团赵俊博:扩散模型让我们能直接修改Token | MEET2026

跳过“逐字生成”!蚂蚁集团赵俊博:扩散模型让我们能直接修改Token | MEET2026

跳过“逐字生成”!蚂蚁集团赵俊博:扩散模型让我们能直接修改Token | MEET2026 一水 2025-1...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
预见未来:96位前沿先锋超万字核心观点总结,抢抓未来产业新高地

预见未来:96位前沿先锋超万字核心观点总结,抢抓未来产业新高地

预见未来:96位前沿先锋超万字核心观点总结,抢抓未来产业新高地 henry 2025-12-11 10:27:...
Meta公开抄阿里Qwen作业,还闭源了…

Meta公开抄阿里Qwen作业,还闭源了…

Meta公开抄阿里Qwen作业,还闭源了… Jay 2025-12-11 11:48:25 来源:量子位 Ja...
MEET2026挤爆了,AI圈今年最该听的20+场演讲&对谈都在这

MEET2026挤爆了,AI圈今年最该听的20+场演讲&对谈都在这

MEET2026挤爆了,AI圈今年最该听的20+场演讲&对谈都在这 西风 2025-12-11 15:...
钉钉又发新版本!把 AI 搬进每一次对话和会议

钉钉又发新版本!把 AI 搬进每一次对话和会议

钉钉又发新版本!把 AI 搬进每一次对话和会议 梦晨 2025-12-11 15:33:51 来源:量子位 A...