javascript - PouchDB 具有“未定义”的文档,而不仅仅是 {} 或 {_id}。如何删除它们?
问题描述
我的pouchdb-find
查询失败是因为有一些错误的数据对象:它们undefined
实际上存储undefined
在数据库中。它们不是{}
或 { _id: 'something'}
,它们实际上是undefined
s。
细节
我在尝试查询非空字段时发现了它。当我查询{$eq: null}
查找这些记录时,我发现了一些奇怪的东西。
询问:
await db.find({ selector: {text: {$gt: null}} });
// or
await db.find({ selector: {text: {$exists: true}} });
结果:
{
docs: [
undefined,
undefined,
undefined,
undefined,
{
_id: 'test-id-1618443059797',
_rev: '3-251568304e939d8d5b688af8c09eaa13'
},
{
_id: 'test-id-1618443082960',
_rev: '3-a60c1dde0e11e14d0a14cd86d2478140'
}
]
}
这似乎可以解释为什么我会收到如下错误。(格式略有不同来自tslog
)。
TypeError Cannot read property 'text' of undefined
error stack:
• index.js:14 getFieldFromDoc
node_modules/.pnpm/pouchdb-selector-core@7.2.2/node_modules/pouchdb-selector-core/lib/index.js:14:18
• index.js:345 <anonymous>
node_modules/.pnpm/pouchdb-selector-core@7.2.2/node_modules/pouchdb-selector-core/lib/index.js:345:25
• index.js:342 rowFilter
node_modules/.pnpm/pouchdb-selector-core@7.2.2/node_modules/pouchdb-selector-core/lib/index.js:342:25
• index.js:319 <anonymous>
node_modules/.pnpm/pouchdb-selector-core@7.2.2/node_modules/pouchdb-selector-core/lib/index.js:319:12
• index.js:318 filterInMemoryFields
node_modules/.pnpm/pouchdb-selector-core@7.2.2/node_modules/pouchdb-selector-core/lib/index.js:318:15
• index.js:1307 <anonymous>
node_modules/.pnpm/pouchdb-find@7.2.2/node_modules/pouchdb-find/lib/index.js:1307:40
其他涉及字段的查询也会发生同样的错误,因为null.<anything>
会不断导致这样的错误。
我认为正在发生的事情
我认为这些是损坏的写入,我试图弄清楚如何在不执行destroy()
. undefined
该州总体上看起来很腐败,因为这些记录有多个。
我试过的
- 彻底调试,通过库代码。帮助我澄清了这个问题,但我还没有解决办法。
- 为了更好地衡量,我尝试了各种方法来删除PouchDB 文档中详述的记录。他们遇到了同样的错误(这对我来说很有意义)
- 因为它们是
undefined
,我无法设置_deleted
属性。即使我可以更改属性,也无法_id
传递给remove
etc。
- 因为它们是
- 使用
.destroy()
,即从 加载数据allDocs
、调用destroy
并将其全部放回。这似乎很棘手,因为在此过程中可能会发生更多数据损坏。
环境
我目前的使用是在 nodejs 环境中。执行通过,ts-node
但我怀疑这很重要。
依赖版本
pouchdb 7.2.2
pouchdb-find 7.2.2
如何删除这些undefined
文件?
除了破坏,还有什么办法可以解决吗?(意思是,我会将数据复制出来,销毁,然后将所有未损坏的数据放回去;但这可能会导致新问题
解决方案
推荐阅读
- python - 用于 Python 脚本的 AutoIT
- php - Dart/Flutter - 发布到 PHP 服务器的文件大小为零字节
- reactjs - 从 API post 方法获取 html 标签到数据中
- discord - 自动停止不和谐的 groovy 机器人
- mongodb - 如何在 C# 中重命名 mongodb 中嵌套数组的文档字段
- javascript - 为什么在 JavaScript 中使用中间变量来返回数组?
- java - 透明背景,同时隐藏一个视图并将其显示为通知
- windows - 批处理窗口 - 用祖父文件夹名称递归替换所有 csv 的第一列
- flutter - 使用 Chewie Video 包时,我得到的 Flutter 在处理错误后被使用
- swift - showBluetoothAccessoryPicker 不显示在屏幕上