Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cosmos DB - Insert Multiple Records with Python

In Cosmos DB I can (thanks to the SO Community) insert a document like so:

data  = {'attribute1':1, 'attribute2': 2}
client.CreateDocument('dbs/databaseName/colls/collectionName/', data)

It would be great if I could insert multiple documents at a time, like how in SQL you can do:

insert into table values (1, 2), (3,4), (5,6)

I understand that you can do bulk uploads with stored procedures, but if I could basically concat a bunch of documents together I think that would work better for me (...or at least save me learning how to write stored produces at this moment).

like image 662
Ben Mayo Avatar asked Oct 17 '22 03:10

Ben Mayo


1 Answers

You're correct in that you can insert multiple documents via a stored procedure.

However: There are no api calls to insert multiple documents at once. You must execute one call per document insert (whether done from your app, or from a stored procedure).

The stored procedure approach will give you a less-chatty set of calls (essentially a single call), and be transactional (all or none succeed).

like image 154
David Makogon Avatar answered Nov 15 '22 07:11

David Makogon