【发布时间】:2019-06-12 16:20:09
【问题描述】:
在使用 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,
});
}
})"
收到任何指点,谢谢。
【问题讨论】: