[英]How do I create a partitioned collection in Cosmos DB with pydocumentdb?
The pydocumentdb.document_client.DocumentClient
object has a CreateCollection()
method, defined here . pydocumentdb.document_client.DocumentClient
对象具有CreateCollection()
方法, 在此定义。
When creating a collection with this method, one needs to specify the database link (already known), the collection (I don't know how to reference it if it hasn't been made) and options. 使用这种方法创建集合时,需要指定数据库链接(已经知道),集合(如果不创建它,我不知道如何引用它)和选项。
Parameters that I would like to control when creating the collection are: 创建集合时我要控制的参数是:
Enums for some of these parameters seem to be defined here , but I don't see any potentially useful HTTP headers in http_constants.py , and I don't see where RUs come in to play or where a cohesive "Collection" object would be passed as a parameter. 其中一些参数的枚举似乎在此处定义,但我在http_constants.py中看不到任何潜在有用的HTTP标头,也看不到RU进入哪里或内聚的“集合”对象在哪里。作为参数传递。
You could refer to the source sample code
from here and the rest api
from here . 你可以参考
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)
Hope it helps you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.