How to populate a CosmosDB collection by command line?

只谈情不闲聊 提交于 2020-07-23 03:59:11

问题


I am developing a set of Scripts for Azure and I would like to know how to populate a CosmosDB collection with az.

Currently, I know how to create a Database and Collection but how to initialize the Database?

  az cosmosdb create \
    --resource-group $RESOURCE_GROUP \
    --name $COSMOS_DB_ACCOUNT
  az cosmosdb database create \
    --resource-group-name $RESOURCE_GROUP \
    --name $COSMOS_DB_ACCOUNT \
    --db-name $COSMOS_DB_NAME
  az cosmosdb collection create \
    --resource-group-name $RESOURCE_GROUP \
    --name $COSMOS_DB_ACCOUNT \
    --collection-name $COSMOS_DB_COLLECTION_NAME \
    --db-name $COSMOS_DB_NAME \
    --partition-key-path $COSMOS_DB_COLLECTION_PARTITION_KEY

Reading the documentation, I didn´t see a solution.


回答1:


az doesn't provide any data-movement options for Cosmos DB.

For the SQL API, you'll either need to create your own command-line tool, or use the Cosmos DB-supplied Data Migration Tool (Windows-only, unlike az), which provides a command-line interface. For example:

dt /s:JsonFile /s.Files:.\inputdata.json /t:DocumentDBBulk /t.ConnectionString:"AccountEndpoint=<name>;AccountKey=<key>;Database=<db>;" /t.Collection:<collname> /t.CollectionThroughput:<throughput>

This has support for the MongoDB API as well, but you can also use native command-line tools such as mongoimport.



来源:https://stackoverflow.com/questions/61077774/how-to-populate-a-cosmosdb-collection-by-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!