繁体   English   中英

如何使用pydocumentdb在Cosmos DB中创建分区集合?

[英]How do I create a partitioned collection in Cosmos DB with pydocumentdb?

pydocumentdb.document_client.DocumentClient对象具有CreateCollection()方法, 在此定义。

使用这种方法创建集合时,需要指定数据库链接(已经知道),集合(如果不创建它,我不知道如何引用它)和选项。

创建集合时我要控制的参数是:

  • 馆藏名称
  • 集合类型(固定大小与分区大小)
  • 分区键
  • RU值
  • 索引策略(或至少能够在某处创建默认模板并将其自动复制到新创建的模板中)

其中一些参数的枚举似乎在此处定义,但我在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM