我正在嘗試使用節點創建Azure文檔數據庫(波斯菊數據庫)分區集合。在node.js中創建Azure DocumentDB分區集合
function _getOrCreateCollectionAsync(databaseUrl, collection){
var collectionUrl = `${databaseUrl}/colls/${collection.name}`,
def = Q.defer();
console.log("getting collection: " + collectionUrl);
client.readCollection(collectionUrl, (err, result) => {
if (err) {
if (err.code == 404) {
console.log("collection " + collection.name + " not found... creating...");
var colOptions = {};
colOptions.offerThroughput = collection.azureOptions.offerThroughput || 10000; //default is 10k
colOptions.partitionKey = ["/data"];
// colOptions.partitionKey = ["data"];
// colOptions.partitionKey = "/data";
// colOptions.partitionKey = "data";
var reqOptions = {
id : collection.name
//, partitionKey : ["/data"]
}
client.createCollection(databaseUrl, reqOptions, colOptions, (err, created) => {
if (err) {
console.log(err);
def.reject(err)
} else {
def.resolve(created);
}
});
} else {
console.log(err);
def.reject(err);
}
} else {
def.resolve(result);
}
});
return def.promise;
}
(請忽略代碼草率,我還在試圖得到它的工作)
當我運行此我得到這個錯誤
.......... working with collection: testCollection
getting collection: dbs/testDb/colls/testCollection
collection testCollection not found... creating...
{ code: 400,
body: '{"code":"BadRequest","message":"Message: {\\"Errors\\":[\\"x-ms-documentdb-partitionkey header cannot be specified for this request\\"]}\\r\\nActivityId: (snip), Request URI: /apps/(snip)/services/(snip)/partitions/(snip)/replicas/(snip)"}',
activityId: '(snip)' }
正如你可以從上面我見有不同的選項來定義分區鍵,它們都返回相同的結果。
我也嘗試使用此示例Create Collection in Azure DocumentDB with Different Partition Mode作爲指導(它在c#中)將其添加到reqOptions中,並指出他需要將分區鍵作爲reqOptions對象的一部分。當我這樣做時,我得到了這個錯誤。
.......... working with collection: testCollection
getting collection: dbs/testDb/colls/testCollection
collection testCollection not found... creating...
{ code: 400,
body: '{"code":"BadRequest","message":"The specified document collection is invalid.\\r\\nActivityId: (snip)"}',
activityId: '(snip)' }
在這一點上我虧本,任何幫助將不勝感激。
由於
的價值是什麼,你要提供在'collection.azureOptions.offerThroughput'?它是否低於2500? –
我從400開始,但是我在發佈的文檔中閱讀過,它必須超過10,000。我提出了10,100,但我又有一個錯誤,說這個價值太高了。所以現在我使用10,000 –