如何使用pydocumentdb在Cosmos数据库中创建分区集合?

2024-05-29 02:38:32 发布

您现在位置:Python中文网/ 问答频道 /正文

pydocumentdb.document_client.DocumentClient对象有一个CreateCollection()方法,定义了here。在

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

创建集合时要控制的参数包括:

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

其中一些参数的枚举似乎是在here中定义的,但我在http_constants.py中看不到任何可能有用的HTTP头,我也看不到ru在哪里发挥作用,也看不到内聚的“Collection”对象将作为参数传递到何处。在


Tags: 对象方法client模板数据库参数here定义
1条回答
网友
1楼 · 发布于 2024-05-29 02:38:32

您可以从here引用source sample code,从here引用{}。在

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)

希望对你有帮助。在

相关问题 更多 >

    热门问题