【问题标题】:Pouchdb giving ReferenceError: t is not defined for map/reduce queriesPouchdb 给出 ReferenceError: t is not defined for map/reduce 查询
【发布时间】:2021-09-09 22:44:55
【问题描述】:

我的数据库中有一个 map reduce 设计文档。但是,当我对其运行任何查询时,它会给我错误ReferenceError: t is not defined。 我设法调试了这个问题,并在 pouchdb 代码中发现了这个问题发生的以下区域。

试图成为 map/reduce 的文档是这样的:

{"uid":"03b72b1c690abacd70ec6a9690ad763a","type":"purchase","order":[{"plan_name":"50000 SMS","sms_count":50000,"active":true,"price":6000,"_id":"7ed7a9474ed051d6296afe966b97bf43","_rev":"1-261f6278bd0eccccfb1785f4d1613619"}],"total_price":6000,"total_sms":50000,"date":1610105466674,"_id":"e9b06cd8cfade9d62d6676c8f3bff806","_rev":"1-6806dc8e13bcc53e8eb8d349c54acd78"}

我的设计文档是:

{
    _id:"_design/for_orders",
    views:{
        find_total_sms:{
            map: function(doc:any){console.log(doc);emit(doc.uid,doc.total_sms);}.toString(),
            reduce:"_sum"
        },
        sms_by_date:{
            map: function(doc:any){emit(doc.date,doc.total_sms)}.toString(),
            reduce: "_sum"
        }
    }
}

我也发起了:

import * as pf from  'pouchdb-find';
PouchDB.plugin(pf);

谁能帮我找出问题所在以及如何解决这个问题?

【问题讨论】:

    标签: pouchdb


    【解决方案1】:

    大家好,我发现了这个问题,不要使用打字稿来定义你的设计文档。 我创建了一个单独的 designs.ts 文件并将我的设计放入其中:

    // @ts-nocheck
    export const DES_FOR_ORDERS={
        _id:"_design/for_orders",
        views:{
            find_total_sms:{
                map: function(doc){console.log(doc);emit(doc.uid,doc.total_sms);}.toString(),
                reduce:"_sum"
            },
            sms_by_date:{
                map: function(doc){emit(doc.date,doc.total_sms)}.toString(),
                reduce: "_sum"
            }
        }
    }
    

    这使它一切正常。 注意//@ts-nocheck 评论,它将有助于禁用特定文件上的打字稿。所以我把我所有的设计都放在了一个designs.ts文件中,并在里面使用了JS来创建我的设计文档。

    它解决了这个问题。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,对我来说,将 map 函数直接分配为字符串解决了它。所以我假设 toString() 方法在这里可能有问题。

      【讨论】:

      • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
      猜你喜欢
      • 2021-03-29
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      • 2015-04-03
      • 1970-01-01
      相关资源
      最近更新 更多