gpt4 book ai didi

azure - Cosmos DB 存储过程在没有 PartitionKey 的情况下无法执行

转载 作者:行者123 更新时间:2023-12-03 00:09:54 27 4
gpt4 key购买 nike

我有一个包含 PartitionKey.i 的集合,它创建了一个接受查询作为参数的存储过程。在此存储过程中,我正在获取一些要更新的文档,但在获取时显示错误,提示当我使用该方法时提供 PartitionKey

public Task<StoredProcedureResponse<TValue>> ExecuteStoredProcedureAsync<TValue>(Uri storedProcedureUri, [Dynamic(new[] { false, true })] params dynamic[] procedureParams);

使用另一种方法时

public Task<StoredProcedureResponse<TValue>> ExecuteStoredProcedureAsync<TValue>(string storedProcedureLink, RequestOptions options, [Dynamic(new[] { false, true })] params dynamic[] procedureParams);

在此方法中,我将 PartitionKey 传递为

new RequestOptions { PartitionKey = new PartitionKey(Undefined.Value)

在存储过程中使用此 RequestOptions 时,不会获取任何文档。

function ABC(query) {
var collection = getContext().getCollection();
var collectionLink = collection.getSelfLink();
var response = getContext().getResponse();
// Validate input.
if (!query) throw new Error("The query is undefined or null.");

tryQueryAndDelete();

function tryQueryAndDelete(continuation) {
var requestOptions = { continuation: continuation };

var isAccepted = collection.queryDocuments(collectionLink, query, requestOptions, function (err, retrievedDocs, responseOptions) {
if (err) throw err;

if (retrievedDocs.length > 0) {
console.log("Doc Found");
} else {
console.log("Doc not Found");

}
});
}

}

有没有办法让我可以在不传递 PartitionKey 的情况下获取文档?

最佳答案

If the collection the stored procedure is registered against is a single-partition collection, then the transaction is scoped to all the documents within the collection. If the collection is partitioned, then stored procedures are executed in the transaction scope of a single partition key. Each stored procedure execution must then include a partition key value corresponding to the scope the transaction must run under.

您可以引用上面的描述,提到here

不可能通过将分区键设置为Undefined.Value来逃避上述规则。在分区集合中执行存储过程时,必须提供分区键。

is there anyway so that I can fetch the documents without passing the PartitionKey?

执行查询sql时,可以将FeedOptions参数中的EnableCrossPartitionQuery设置为true。(有性能瓶颈)。

希望对您有帮助。

关于azure - Cosmos DB 存储过程在没有 PartitionKey 的情况下无法执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50044575/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com