[英]How do I create a partitioned collection in Cosmos DB with pydocumentdb?
pydocumentdb.document_client.DocumentClient
对象具有CreateCollection()
方法, 在此定义。
使用这种方法创建集合时,需要指定数据库链接(已经知道),集合(如果不创建它,我不知道如何引用它)和选项。
创建集合时我要控制的参数是:
其中一些参数的枚举似乎在此处定义,但我在http_constants.py中看不到任何潜在有用的HTTP标头,也看不到RU进入哪里或内聚的“集合”对象在哪里。作为参数传递。
你可以参考source sample code
从这里和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)
希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.