Exporting collection from a Azure MongoDB

时间:2018-02-03 09:34:17

标签: mongodb azure azure-cosmosdb

So I have a MongoDB in an Azure Cosmos DB service. It contains a collection of 1500 documents and I want to download this whole collection in a JSON format. I've tried several methods without success, namely

test_collection.find({})

Which gave me a cursor timeout. Using

{ timeout : false }

Did not help. Then I tried to use mongoexport:

mongoexport -h host_name --port 1234 -u user_name -p password 
-d admin -c collection_name -o data.json --ssl

which gives me 0 exported records. The firewall IP access control is off and I can connect to the database through Mongo shell just fine. Trying to export other collections doesn't work either. Also, it has to be by ssl otherwise I get a "database not found" right away.

I've thought about using skip and limit but it doesn't seem to be a good idea with large (and expanding) collections? Could someone please give me some advise as to how I best achieve or overcome these obstacles to download my collection? It doesn't matter how, I just simply need to download the collection. Thank you.

1 个答案:

答案 0 :(得分:3)

您可能有一些不正确的参数和缺少的参数:

  • 您确定数据库名称是admin吗?
  • 您需要指定--sslAllowInvalidCertificates
  • 对于主机/端口:这应该类似于:

    /h yourcosmosaccount.documents.azure.com:10255

如果您看一下"快速启动"在Cosmos数据库设置中的选项卡中,您将看到mongo的命令行字符串(例如,示例中为mongo.exe)。只需获取这些参数并将其用于mongoexport

我刚刚针对我的一个示例Cosmos DB(MongoDB API)数据库运行此操作,没有任何问题:

mongoexport image