0

根据此https://docs.cloudant.com/document.html#bulk-operations 我正在尝试将多个文档插入到我的 cloudant 数据库中,但出现错误:

{
  "error": {
    "statusCode": 400,
    "name": "Error",
    "request": {
      "method": "POST",
      "headers": {
        "content-type": "application/json",
        "accept": "application/json"
      },
      "uri": "https://XXXXXX:XXXXXX@8f7fc7f0-766b-4429-b060-4ef1c01f7665-bluemix.cloudant.com/ttt/_bulk_docs",
      "body": "[{\"name\":\"Nicholas\",\"_id\":\"96f898f0-f6ff-4a9b-aac4-503992f31b01\",\"_attachments\":{},\"age\":45,\"gender\":\"male\"},{\"name\":\"Taylor\",\"_id\":\"5a049246-179f-42ad-87ac-8f080426c17c\",\"_attachments\":{},\"age\":50,\"gender\":\"male\"},{\"name\":\"Owen\",\"_id\":\"d1f61e66-7708-4da6-aa05-7cbc33b44b7e\",\"_attachments\":{},\"age\":51,\"gender\":\"male\"}]"
    },
    "description": "couch returned 400",
    "scope": "couch",
    "reason": "Request body must be a JSON object",
    "error": "bad_request",
    "stack": "Error: Request body must be a JSON object\n    at Request._callback (/nodejsAction/node_modules/cloudant-nano/lib/nano.js:247:15)\n    at Request.self.callback (/nodejsAction/node_modules/request/request.js:186:22)\n    at emitTwo (events.js:106:13)\n    at Request.emit (events.js:191:7)\n    at Request.<anonymous> (/nodejsAction/node_modules/request/request.js:1081:10)\n    at emitOne (events.js:96:13)\n    at Request.emit (events.js:188:7)\n    at IncomingMessage.<anonymous> (/nodejsAction/node_modules/request/request.js:1001:12)\n    at IncomingMessage.g (events.js:291:16)",
    "message": "Request body must be a JSON object",
    "errid": "non_200",
    "headers": {
      "statusCode": 400,
      "x-couchdb-body-time": "0",
      "cache-control": "must-revalidate",
      "uri": "https://XXXXXX:XXXXXX@8f7fc7f0-766b-4429-b060-4ef1c01f7665-bluemix.cloudant.com/ttt/_bulk_docs",
      "x-cloudant-backend": "bm-cc-dal-01",
      "date": "Sat, 20 May 2017 12:11:37 GMT",
      "content-type": "application/json",
      "via": "1.1 lb1.bm-cc-dal-01 (Glum/1.34.0)",
      "x-couch-request-id": "fed1512052",
      "x-content-type-options": "nosniff",
      "strict-transport-security": "max-age=31536000"
    }
  }
}

我从示例文档中获取了输入 Json 并在线检查了 JSON 验证器,它似乎没问题。我做错了什么?

4

1 回答 1

4

请求正文似乎缺少该docs属性。参考文档提供了此示例:

{
  "docs": [
           {
            "name": "Nicholas",
            "age": 45,
            "gender": "female",
            "_id": "96f898f0-f6ff-4a9b-aac4-503992f31b01",
            "_rev": "1-54dd23d6a630d0d75c2c5d4ef894454e"
           },
           {
            "_id": "d1f61e66-7708-4da6-aa05-7cbc33b44b7e",
            "_rev": "1-a2b6e5dac4e0447e7049c8c540b309d6",
            "_deleted": true
           }
         ]
}
于 2017-05-20T19:55:52.690 回答