Pouchdb 给出 ReferenceError: t is not defined for map/reduce 查询

问题描述

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

enter image description here

enter image description here

试图映射/减少的文档是这样的:

ReferenceError: t is not defined

我的设计文档是:

{"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"
        }
    }
}

谁能帮我找出哪里出了问题以及如何解决这个问题?

解决方法

所有权利的人,我发现了问题,不要使用打字稿来定义您的设计文档。 我创建了一个单独的 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 来创建我的设计文档。

它解决了这个问题。