问题描述
我有一个具有PartitionKey的集合.我有一个存储过程,该存储过程接受查询作为参数.在此存储过程中,我正在获取一些文档以进行更新,但是在获取文档时显示了一条错误消息,当我使用方法
I have a collection which has PartitionKey.i have a made a stored procedure which accepts query as a parameter. in this stored procedure, I'm fetching some documents to update but while fetching it shows an error saying provide PartitionKey when I use the method
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传递为
in this method, I have Pass the PartitionKey as
new RequestOptions { PartitionKey = new PartitionKey(Undefined.Value)
在存储过程中使用此RequestOptions时,未提取文档.
while using this RequestOptions in the Stored Procedure no Document is Fetch.
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的信息?
is there anyway so that I can fetch the documents without passing the PartitionKey?
推荐答案
您可以参考上面提到的这里.
You could refer to the description above which mentioned here.
通过将分区键设置为Undefined.Value
来逃避上述规则是不可能的.在分区集合中执行存储过程时,必须提供分区键.
It's impossible to escape the above rule by setting the partition-key to Undefined.Value
. You must provide the partition key when you execute stored procedure in partitioned collection.
执行查询sql时,可以在FeedOptions参数中将EnableCrossPartitionQuery
设置为true
.(存在性能瓶颈).
You could set EnableCrossPartitionQuery
to true
in FeedOptions parameter when executing query sql.(has performance bottleneck).
希望它对您有帮助.
这篇关于没有PartitionKey,Cosmos DB存储过程无法执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!