DocumentDB:bulkImport存储的Proc-在Array/JSON问题上出现400错误 [英] DocumentDB: bulkImport Stored Proc - Getting 400 Error on Array/JSON issue

查看:66
本文介绍了DocumentDB:bulkImport存储的Proc-在Array/JSON问题上出现400错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试图为documentDB API执行标准示例bulkImport sproc,但似乎无法将其传递给对象数组.我总是收到400个错误尽管文档给出了发送对象数组的明确指示 ..非常令人沮丧.

I'm simply trying to execute the standard example bulkImport sproc for documentDB API and I can't seem to pass it an array of objects. I always get 400 errors despite the documentation giving clear direction to send an array of objects .. very frustrating.

其他详细信息:即使我将数组包装在对象中,且该数组的属性为"items",并将其包含在我的存储过程中,它仍然会错误地指出相同的错误请求,它必须是对象或JSON序列化.当我尝试在发送前执行JSON.stringify(docs)时,另一端无法解析.

Additional details: Even if I wrap the array in an object with the array under a property of 'items' and include it in my sproc it still errors out saying the same bad request, needs to be an object or JSON-serialized. When I try to do JSON.stringify(docs) before sending it fails to parse on the other side.

错误请求:文档正文必须是一个对象或代表JSON序列化对象的字符串.

Bad Request: The document body must be an object or a string representing a JSON-serialized object.

bulkInsert.js: https://github.com. com/Azure/azure-documentdb-js-server/blob/master/samples/stored-procedures/BulkImport.js

bulkInsert.js: https://github.com/Azure/azure-documentdb-js-server/blob/master/samples/stored-procedures/BulkImport.js

我的代码(使用documentdb-util进行异步处理):

My Code (using documentdb-util for async):

execProc(docs, insertProc);
async function execProc(docs, insertProc){
    let database = await dbUtil.database('test');
    let collection = await dbUtil.collection(database, 'test');
    let procInstance = await dbUtil.storedProcedure(collection, insertProc);
    try{
        let result = await dbUtil.executeStoredProcedure(procInstance, docs);
        console.log(result);
    } catch(e){
        console.log(e.body)
    }  
}

标题

对象{Cache-Control:"no-cache",x-ms-version:"2017-11-15", 用户代理:"win32/10.0.16299 Nodejs/v8.9.0 documentdb-nodejs-s…", x-ms-date:"2017年12月11日星期一,格林尼治标准时间", 接受:"application/json" 授权:myauth 缓存控制:不缓存" 内容类型:"application/json" 用户代理:"win32/10.0.16299 Nodejs/v8.9.0 documentdb-nodejs-sdk/1.14.1" x-ms-date:"2017年12月11日星期一格林尼治标准时间" x-ms-version:"2017-11-15"

Object {Cache-Control: "no-cache", x-ms-version: "2017-11-15", User-Agent: "win32/10.0.16299 Nodejs/v8.9.0 documentdb-nodejs-s…", x-ms-date: "Mon, 11 Dec 2017 07:32:29 GMT", Accept:"application/json" authorization: myauth Cache-Control:"no-cache" Content-Type:"application/json" User-Agent:"win32/10.0.16299 Nodejs/v8.9.0 documentdb-nodejs-sdk/1.14.1" x-ms-date:"Mon, 11 Dec 2017 07:32:29 GMT" x-ms-version:"2017-11-15"

路径 "/dbs/myDB/colls/myColl/sprocs/myBulkInsert"

Path "/dbs/myDB/colls/myColl/sprocs/myBulkInsert"

参数

Array(3)[对象,对象,对象] 长度:3

Array(3) [Object, Object, Object] length:3

0:Object {id:"0001",类型:甜甜圈",名称:蛋糕",...}

0:Object {id: "0001", type: "donut", name: "Cake", …}

1:Object {id:"0002",类型:"donut",名称:"Raised",…}

1:Object {id: "0002", type: "donut", name: "Raised", …}

2:Object {id:"0003",类型:甜甜圈",名称:老式",…}

2:Object {id: "0003", type: "donut", name: "Old Fashioned", …}

[{
    "id": "0001",
    "type": "donut",
    "name": "Cake",
    "ppu": 0.55
},
{
    "id": "0002",
    "type": "donut",
    "name": "Raised",
    "ppu": 0.35
},
{
    "id": "0003",
    "type": "donut",
    "name": "Old Fashioned",
    "ppu": 0.25
}]

推荐答案

文档"必须是参数数组的数组,否则,过程执行者会将它们视为过程的多个参数,而不是单个数组-参数.

The "docs" must be an array of array of params, otherwise, the procedure executor will treat them as multiple params of the procedure, not a single-array-param.

这篇关于DocumentDB:bulkImport存储的Proc-在Array/JSON问题上出现400错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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