I want to do bulk insert in CosmosDB collections. But bulk insertion library is only available for .NET and Java.
I found another alternative as StoredProcedure but in that also I have to store using for loop.
sproc = {
'id': 'storedProcedure' + str(uuid.uuid4()),
'body': (
'function (data) {' +
' var client = getContext().getCollection();' +
' client.createDocument(client.getSelfLink(), data, {}, function(err, docCreated, options) { ' +
' if(err) throw new Error(\'Error while creating document: \' + err.message);' +
' else {' +
' getContext().getResponse().setBody(1);' +
' }' +
' });}')
}
created_sproc = client.CreateStoredProcedure(coll_link, sproc)
proc_id = sproc['id']
proc_query = "select * from r where r.id = '{0}'".format(proc_id)
proc = list(client.QueryStoredProcedures(coll_link, proc_query))[0]
proc_link = proc['_self']
print(proc)
client.ExecuteStoredProcedure(proc_link, [data])
Any alternative for bulk executor in python?