PlagueHO / CosmosDB

PowerShell Module for working with Azure Cosmos DB databases, collections, documents, attachments, offers, users, permissions, triggers, stored procedures and user defined functions.
http://dscottraynsford.com
MIT License
154 stars 46 forks source link

Request to Support Bulk Upload for New-CosmosDbDocument #425

Closed gitmopp closed 3 years ago

gitmopp commented 3 years ago

New-CosmosDbDocument can only store a single document, e.g. New-CosmosDbDocument -Context $cosmosDbContext -CollectionId $container -DocumentBody $document -PartitionKey $id

The Azure portal allows the upload of a JSON file which is much faster then creating a single document. I checked the body and it uses the "operationType: Create" to bulk upload multiple documents at once (limit is 100?)

-Body "[
{`"operationType`":`"Create`",`"resourceBody`":{`"id`":`"12345fa0-3d88-4bdc-bd01-94843009b513`",`"Address`":`"10.10.10.1`"},`"partitionKey`":`"[\`"12345fa0-3d88-4bdc-bd01-94843009b513\`"]`"},
{`"operationType`":`"Create`",`"resourceBody`":{`"id`":`"12345324-f997-4a87-8dd9-f45531c97027`",`"Address`":`"10.10.10.2`"},`"partitionKey`":`"[\`"12345324-f997-4a87-8dd9-f45531c97027\`"]`"},
{`"operationType`":`"Create`",`"resourceBody`":{`"id`":`"123456cf-5fe7-4cee-aa51-1b6112da5484`",`"Address`":`"10.10.10.3`"},`"partitionKey`":`"[\`"123456cf-5fe7-4cee-aa51-1b6112da5484\`"]`"}
]"

Is it possible to add a bulk upload function?

Raag007 commented 3 years ago

@gitmopp - I was able to upload a bulk document with no issues. Let me know if you need any help on this.

I'm using Powershell and @PlagueHO tools to upload the documents to Cosmos Container. Thank you.

gitmopp commented 3 years ago

@gitmopp - I was able to upload a bulk document with no issues. Let me know if you need any help on this.

I'm using Powershell and @PlagueHO tools to upload the documents to Cosmos Container. Thank you.

Which command did you use? For myself I created a workaround with a 3rd party application.

Raag007 commented 3 years ago

@gitmopp - I was able to upload a bulk document with no issues. Let me know if you need any help on this. I'm using Powershell and @PlagueHO tools to upload the documents to Cosmos Container. Thank you.

Which command did you use? For myself I created a workaround with a 3rd party application.

Good to know.

Here are the commands which I have used.

$document = $getHandler | ConvertTo-Json -Depth 50
New-CosmosDbDocument -Context $cosmosDbContext -CollectionId $containerName -DocumentBody $document -PartitionKey $getHandler.partitionKey
gitmopp commented 3 years ago
$document = $getHandler | ConvertTo-Json -Depth 50
New-CosmosDbDocument -Context $cosmosDbContext -CollectionId $containerName -DocumentBody $document -PartitionKey $getHandler.partitionKey

Thank you