pydocumentdb.document_client.DocumentClient
对象有一个 CreateCollection()
方法,定义为 here .
使用此方法创建集合时,需要指定数据库链接(已经知道)、集合(如果没有创建,我不知道如何引用它)和选项。
创建集合时我想控制的参数是:
- 集合名称
- 集合类型(固定大小与分区)
- 分区键
- RU 值
- 索引政策(或者至少能够在某处创建默认模板并自动将其复制到新创建的模板)
其中一些参数的枚举似乎已定义 here ,但我在 http_constants.py 中没有看到任何可能有用的 HTTP header ,而且我没有看到 RU 在哪里发挥作用,也没有看到内聚的“集合”对象将作为参数传递。
最佳答案
您可以引用here中的源示例代码
以及 here 中的 rest api
.
import pydocumentdb;
import pydocumentdb.errors as errors
import pydocumentdb.document_client as document_client
config = {
'ENDPOINT': 'https://***.documents.azure.com:443/',
'MASTERKEY': '***'
};
# Initialize the Python DocumentDB client
client = document_client.DocumentClient(config['ENDPOINT'], {'masterKey': config['MASTERKEY']})
databaseLink = "dbs/db"
coll = {
"id": "testCreate",
"indexingPolicy": {
"indexingMode": "lazy",
"automatic": False
},
"partitionKey": {
"paths": [
"/AccountNumber"
],
"kind": "Hash"
}
}
collection_options = { 'offerThroughput': 400 }
client.CreateCollection(databaseLink , coll, collection_options)
希望对您有帮助。
关于python - 如何使用 pydocumentdb 在 Cosmos DB 中创建分区集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49324754/