使用PouchDB开发应用程序一段时间后,我现在开始我的第一次尝试与远程CouchDB实例同步。目前,我仅与可安装的OSX CouchDB应用程序提供的CouchDB同步。
文档似乎可以很好地同步,但是我在使用特定视图时遇到了麻烦。我检查过它是有效的JS,看不到错误。
我将每个视图存储在其自己的设计文档中,我读过的这是最佳实践。
到目前为止,我已经尝试过:
toLowerCase()
(确实没有理由,只是为了检查)由于使用了现代JS功能,其他人在视图同步方面遇到了问题,但是我相信我已经用ES5编写了我的文章,我读过这是必需的。
以下是视图定义代码:
const ddoc = {
_id: '_design/title-only',
views: {
'title-only': {
map: function titleOnly(doc) {
if (doc.type && doc.type === 'song' && doc.title) {
emit(doc.title.toLowerCase(), {
id: doc._id,
title: doc.title,
authors: doc.authors,
starred: doc.starred || false,
labels: doc.labels || [],
createdAt: doc.createdAt,
});
}
}.toString(),
},
}
};
我收到“ compilation_error”类型的错误。
以下是错误消息:
"Compilation of the map function in the 'title-only' view failed: Expression does not eval to a function. (function titleOnly(doc) {
if (doc.type && doc.type === 'song' && doc.title) {
emit(doc.title.toLowerCase(), {
id: doc._id,
title: doc.title,
authors: doc.authors,
starred: doc.starred || false,
labels: doc.labels || [],
createdAt: doc.createdAt,
});
}
})"
感谢所有收到的指针,谢谢。
答案 0 :(得分:0)
不要使用命名函数。
换句话说,替换为:
map: function titleOnly(doc) {
与此:
map: function(doc) {