Cosmos DB-使用Python插入多个记录 [英] Cosmos DB - Insert Multiple Records with Python

查看:64
本文介绍了Cosmos DB-使用Python插入多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Cosmos DB中,我可以(由于SO社区)像这样插入文档:

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)

如果我一次可以插入多个文档,就像在SQL中可以执行的操作那样,那将是很棒的事情:

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).

推荐答案

您是正确的,因为您可以通过存储过程插入多个文档.

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

但是:没有api调用可一次插入多个文档.您必须为每个文档插入执行一次调用(无论是从您的应用程序还是从存储过程完成).

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).

这篇关于Cosmos DB-使用Python插入多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆