就地更新功能得到“500(内部服务器错误)”
In place update function get "500 (Internal Server Error)"
我使用 couchDB 3.2.1。我有一个包含视图和现在更新功能的设计文档。我在尝试 运行 函数时得到 500(内部服务器错误),使用 PUT 和 fetchAPI 传递文档:
http://my.company.xyz:5984/brunel/_design/brunel/_update/customerPrefs/5509
我尝试通过在函数末尾返回文档来进行调试,但仍然遇到同样的问题。
设计文档如下所示:
"_id": "_design/brunel",
"_rev": "11-33c446a585aa4a63f3f848bd4979d721",
"views": {
"productCategoryNames": {
"map": "function (doc) { if ((doc.recordType === 'product') && doc.categoryName && doc.categoryCode){ emit([doc.categoryCode, doc.categoryName], null); }}",
"reduce": "_count"
},
"invoiceNumbers": {
"map": "function (doc) { if (doc.recordType === 'invoice'){ emit(doc.invoiceNumber, null); }}",
"reduce": "_count"
},
"supplierNames": {
"map": "function (doc) { if ((doc.recordType === 'supplier') && doc.supplierName){ emit(doc.supplierName, null); }}",
"reduce": "_count"
},
"productNames": {
"map": "function (doc) { if ((doc.recordType === 'product') && doc.description){ emit(doc.description, null); }}",
"reduce": "_count"
},
"customerNames": {
"map": "function (doc) { if ((doc.recordType === 'customer') && doc.customerName){ emit(doc.customerName, null); }}",
"reduce": "_count"
},
"batchReceiveDates": {
"map": "function (doc) { if (doc.recordType === 'batch'){ emit(doc.batchNumber, null); }}"
}
},
"updates": {
"customerPrefs": "function (doc, req){ return [doc]; }"
}
}
我认为我在设计文档中声明更新函数的方式可能有问题。
我的目标是使用就地更新函数来传递密钥对,这将是数组中的 stored/appended,这是现有文档的一部分。
couchDB 日志显示以下错误:
[error] 2019-06-23T19:11:48.879976Z couchdb@127.0.0.1 <0.6521.378> 6734daf161 OS Process Error <0.14007.353> :: {<<"render_error">>,<<"undefined response from update function">>}
感谢 Flimzy 指出函数必须 return 两个值。我还发现查看 couchDB 日志文件对于调试更新处理程序中的 JavaScript 错误很有用。
我使用 couchDB 3.2.1。我有一个包含视图和现在更新功能的设计文档。我在尝试 运行 函数时得到 500(内部服务器错误),使用 PUT 和 fetchAPI 传递文档: http://my.company.xyz:5984/brunel/_design/brunel/_update/customerPrefs/5509
我尝试通过在函数末尾返回文档来进行调试,但仍然遇到同样的问题。
设计文档如下所示:
"_id": "_design/brunel",
"_rev": "11-33c446a585aa4a63f3f848bd4979d721",
"views": {
"productCategoryNames": {
"map": "function (doc) { if ((doc.recordType === 'product') && doc.categoryName && doc.categoryCode){ emit([doc.categoryCode, doc.categoryName], null); }}",
"reduce": "_count"
},
"invoiceNumbers": {
"map": "function (doc) { if (doc.recordType === 'invoice'){ emit(doc.invoiceNumber, null); }}",
"reduce": "_count"
},
"supplierNames": {
"map": "function (doc) { if ((doc.recordType === 'supplier') && doc.supplierName){ emit(doc.supplierName, null); }}",
"reduce": "_count"
},
"productNames": {
"map": "function (doc) { if ((doc.recordType === 'product') && doc.description){ emit(doc.description, null); }}",
"reduce": "_count"
},
"customerNames": {
"map": "function (doc) { if ((doc.recordType === 'customer') && doc.customerName){ emit(doc.customerName, null); }}",
"reduce": "_count"
},
"batchReceiveDates": {
"map": "function (doc) { if (doc.recordType === 'batch'){ emit(doc.batchNumber, null); }}"
}
},
"updates": {
"customerPrefs": "function (doc, req){ return [doc]; }"
}
}
我认为我在设计文档中声明更新函数的方式可能有问题。
我的目标是使用就地更新函数来传递密钥对,这将是数组中的 stored/appended,这是现有文档的一部分。
couchDB 日志显示以下错误:
[error] 2019-06-23T19:11:48.879976Z couchdb@127.0.0.1 <0.6521.378> 6734daf161 OS Process Error <0.14007.353> :: {<<"render_error">>,<<"undefined response from update function">>}
感谢 Flimzy 指出函数必须 return 两个值。我还发现查看 couchDB 日志文件对于调试更新处理程序中的 JavaScript 错误很有用。