尝试在CouchDB(Cloudant)数据库上使用批量文档创建时出现Json错误
按此 我试图将多个文档插入cloudant数据库,但出现错误:尝试在CouchDB(Cloudant)数据库上使用批量文档创建时出现Json错误,json,ibm-cloud,couchdb,cloudant,couchdb-nano,Json,Ibm Cloud,Couchdb,Cloudant,Couchdb Nano,按此 我试图将多个文档插入cloudant数据库,但出现错误: { "error": { "statusCode": 400, "name": "Error", "request": { "method": "POST", "headers": { "content-type": "application/json", "accept": "application/json" }, "ur
{
"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"
}
}
}
{
“错误”:{
“状态代码”:400,
“名称”:“错误”,
“请求”:{
“方法”:“发布”,
“标题”:{
“内容类型”:“应用程序/json”,
“接受”:“应用程序/json”
},
“uri”:https://XXXXXX:XXXXXX@8f7fc7f0-766b-4429-b060-4ef1c01f7665-bluemix.cloudant.com/ttt/_bulk_docs”,
“身体:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,“:\“d1f61e66-7708-4da6-aa05-7cbc33b44b7e\”,“\u附件\”:{},\”年龄\“:51,\”性别\“:\”男性\“}”
},
“说明”:“沙发返回400”,
“范围”:“沙发”,
“原因”:“请求主体必须是JSON对象”,
“错误”:“错误的请求”,
“堆栈”:“错误:请求正文在请求时必须是JSON对象。\n回调(/nodejsAction/node\u modules/cloudant nano/lib/nano.js:247:15)\n在Request.self.callback(/nodejsAction/node\u modules/Request/Request.js:186:22)\n在emitTwo(events.js:106:13)\n在Request.emit(events.js:191:7)\n在请求时。(/nodejsAction/node\u modules/request/request.js:1081:10)\n at emitOne(events.js:96:13)\n at request.emit(events.js:188:7)\n at IncomingMessage.(/nodejsAction/node\u modules/request/request.js:1001:12)\n at IncomingMessage.g(events.js:291:16)”,
“消息”:“请求正文必须是JSON对象”,
“errid”:“非200”,
“标题”:{
“状态代码”:400,
“x-couchdb-body-time”:“0”,
“缓存控制”:“必须重新验证”,
“uri”:https://XXXXXX:XXXXXX@8f7fc7f0-766b-4429-b060-4ef1c01f7665-bluemix.cloudant.com/ttt/_bulk_docs”,
“x-cloudant-backend”:“bm-cc-dal-01”,
“日期”:“2017年5月20日星期六12:11:37 GMT”,
“内容类型”:“应用程序/json”,
“via”:“1.1 lb1.bm-cc-dal-01(Glum/1.34.0)”,
“x-coach-request-id”:“fed1512052”,
“x-content-type-options”:“nosniff”,
“严格的运输安全”:“最大年龄=31536000”
}
}
}
我从示例文档中获取了输入Json,并在Json验证器上进行了在线检查,似乎一切正常。
我做错了什么?请求正文似乎缺少
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
}
]
}
请求正文似乎缺少
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
}
]
}