MongoDB:如何将集合从 MongoDB 正确导出到我的计算机? [英] MongoDB: How to properly export a collection from MongoDB to my computer?

查看:48
本文介绍了MongoDB:如何将集合从 MongoDB 正确导出到我的计算机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下数据库和相关集合scows.tasks,我如何将其导出 2GB 用于存储目的以腾出空间?

Given the following database and related collection scows.tasks, how do I export 2GB it for storage purposes so to make space?

我一直在尝试使用各种方法来做到这一点,但都没有奏效:

I have been trying to do it using various ways but none of them worked:

mongoexport --verbose --db scows --collection tasks --out tasks.json --verbose

mongoexport -vvvv --db scows --username='my_username' --password='my_passwd' --collection tasks --out /home/to/Desktop/storageMongo/tasks.json -f 'my_passwd'

mongoexport --host=127.0.0.1 --db scows --collection tasks --out tasts.json

在这样做时,我总是得到完全相同的错误:

And in doing this I always got the same exact error:

2020-02-13T12:55:17.183-0500 将监听 SIGTERM、SIGINT 和SIGKILL 2020-02-13T12:55:20.690-0500 连接数据库服务器时出错:否可访问的服务器

2020-02-13T12:55:17.183-0500 will listen for SIGTERM, SIGINT, and SIGKILL 2020-02-13T12:55:20.690-0500 error connecting to db server: no reachable servers

我用来解决问题的帖子,但不幸的是没有帮助我:

Posts I used to solve the problem but that unfortunately didn't help me out:

1) 我用过这个但什么也没发生

2) 这个也和上面的结果一样

2) This also but same results as above

3) 这个来源很有用,但没有帮助我找出问题

3) This source was useful but didn't help me find out the problem

4) 最后这个帮助我命令,但我总是有同样的错误.

4) And lastly this one to help me with the command but I always had the same error.

5) 同样如官方文档中所述,我使用我的 Ubuntu 18.04 shell 作为终端来输入命令,而不是 mongo shell.

5) Also as mentioned in the official documentation I am using my Ubuntu 18.04 shell as terminal to input the command instead of the mongo shell.

如何将集合从 MongoDB 正确导出到我的计算机?

How do I properly export a collection from MongoDB to my computer?

推荐答案

尝试建议的选项之一(Ubuntu 终端):

Try one of suggested option (Ubuntu terminal):

#localhost:27017 security disabled
mongoexport --db scows --collection tasks --out /tmp/tasks.json

#some_ip:some_port security disabled
mongoexport --host="some_ip:some_port" --db scows --collection tasks --out /tmp/tasks.json

#some_ip:some_port security enabled
mongoexport --host="some_ip:some_port" --username=user --password=pass --db scows --collection tasks --out /tmp/tasks.json

这会将 JSON 文件(无压缩)导出到 /tmp 目录

This will export JSON file (no compression) into /tmp directory

但是如果你用mongodump命令导出,你可以压缩导出的数据

But if you export with mongodump command, you can compress your exported data

mongodump --host="some_ip:some_port" --username=user --password=pass --db scows --collection tasks --gzip --out /tmp

这会将 BSON 结构化文件(压缩)导出到 /tmp/scows 目录

This will export BSON structured files (compressed) into /tmp/scows directory

从 MongoDB Atlas 导出,使用这个:

Export from MongoDB Atlas, use this:

mongoexport --uri="mongodb+srv://username:password@vessel-tracker-cluster-x2lpw.mongodb.net/scows" --collection tasks --out /tmp/tasks.json

<小时>

2020-02-13T20:20:51.387+0100    connected to: mongodb+srv://[**REDACTED**]@vessel-tracker-cluster-x2lpw.mongodb.net/scows
2020-02-13T20:20:52.522+0100    [........................]  scows.tasks  0/XXX  (0.0%)
2020-02-13T20:20:52.642+0100    [########################]  scows.tasks  XXX/XXX  (100.0%)
2020-02-13T20:20:52.643+0100    exported XXX records

编辑 2: 用户有 DNS 问题,忽略 --uri 参数并连接到本地主机.将公共 DNS 添加到 resolve.conf,mongoexport 能够导出数据

EDIT 2: User has DNS issue which ignores --uri parameter and connects to localhost. Adding public DNS to resolve.conf, mongoexport was able to export the data

这篇关于MongoDB:如何将集合从 MongoDB 正确导出到我的计算机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆