简体   繁体   English

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

[英]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: 创建集合时我要控制的参数是:

  • name of collection 馆藏名称
  • type of collection (fixed size vs. partitioned) 集合类型(固定大小与分区大小)
  • partition keys 分区键
  • RU value RU值
  • Indexing policy (or at least be able to create a default template somewhere and automatically copy it to the newly created one) 索引策略(或至少能够在某处创建默认模板并将其自动复制到新创建的模板中)

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.

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