使用Cosmos SP向上插入时出现400错误 [英] 400 error when upsert using Cosmos SP

查看:90
本文介绍了使用Cosmos SP向上插入时出现400错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下SP

I'm trying to execute the below SP

function createMyDocument() {
    var collection = getContext().getCollection();

    var doc = {
        "someId": "123134444",
    };
    var options = {};
    options['PartitionKey'] =  ["someId"];

    var isAccepted = collection.upsertDocument(collection.getSelfLink(), doc, options, function (error, resources, options) {

    });

}

并且波斯菊不断抱怨分区键出问题

and cosmos keeps on complaining that there's something wrong with the partition key

    { code: 400,
      body: '{"code":"BadRequest","message":"Message: {\\"Errors\\":
[\\"PartitionKey extracted from document doesn\'t match the one specified in the header\\"]}
    }

有人知道如何在options中传递partion密钥,以便它通过此验证吗?

Does anyone have any idea how to pass in the partion key in options so it gets pass this validation ?

推荐答案

弄清楚了.错误在于我们如何调用存储的过程.

Figured it out. The error was with how we call the stored proc.

我们如何做到

 client.executeStoredProcedure('dbs/db1/colls/coll-1/sprocs/createMyDocument',
        {},
        {} //Here you have to pass in the partition key

);

必须如何

     client.executeStoredProcedure('dbs/db1/colls/coll-1/sprocs/createMyDocument',
            {},
            {"partitionKey": "43321"} 
);

这篇关于使用Cosmos SP向上插入时出现400错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆