没有PartitionKey,Cosmos DB存储过程没有执行

时间:2018-04-26 13:42:31

标签: azure azure-cosmosdb

我有一个集合,它有一个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的情况下获取文档?

1 个答案:

答案 0 :(得分:0)

  

如果存储过程注册的集合是a   单分区集合,然后将事务范围限定为所有   集合中的文档。如果集合是分区的,   然后存储过程在a的事务范围内执行   单分区键。然后必须执行每个存储过程   包括对应于范围的分区键值   交易必须在。

下运行

您可以参考上面提到here的说明。

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

  

无论如何都是这样我可以在不通过的情况下获取文件   PartitionKey?

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

希望它对你有所帮助。