【问题标题】:This view works in PouchDB but why does it fail to sync with CouchDB?此视图在 PouchDB 中有效,但为什么无法与 CouchDB 同步?
【发布时间】: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,
                                    });
                                }
                            })"

收到任何指点,谢谢。

【问题讨论】:

    标签: couchdb pouchdb


    【解决方案1】:

    不要使用命名函数。

    换句话说,替换这个:

    map: function titleOnly(doc) {
    

    用这个:

    map: function(doc) {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 1970-01-01
      • 2018-08-21
      相关资源
      最近更新 更多