【问题标题】:PouchDb with SQLite, out of memory error on query带有 SQLite 的 PouchDb,查询时出现内存不足错误
【发布时间】:2016-11-16 01:41:00
【问题描述】:

我有一个 pouch 数据库,其中包含数百个 1 Mo 的文档,因此总大小约为 100 Mo。这是一个 Android Cordova 应用程序,我正在使用:

  • PouchDb 5.4.5
  • cordova-plugin-sqlite-2 1.0.4

每个文档都是这样的:

{
    data: '...', // Very long string of 1 Mo
    filename: 'myFile', // Name of a file
    index: 34 // An integer
}

我想对此数据库进行查询以列出所有按文件名和索引索引的文档,而不检索很重的 data 属性。

所以我做了这样的视图:

var designDoc = {
    _id: '_design/getByFilenameAndIndex',
    views: {}
};

mapFunction = function(doc){
    emit(doc.filename + '/' + doc.index);
}

designDoc.views['getByFilenameAndIndex'] = { map: mapFunction.toString() };

myDb.put(designDoc);

但是当我尝试查询我的数据库时,像这样:

myDb.query('getByFilenameAndIndex', {include_docs: false}).then(function(docsByFilenameAndIndex){
    console.log(docsByFilenameAndIndex);
});

我收到以下错误:

为什么我有这个错误?我的设备(Android 6)上仍然有 900 Mo 的内存可用,而且我什至不包括文档。如果我的 db 小于 20 Mo,它可以正常工作。

在使用 SQLite 插件之前,它在 40 Mo 的 db 上也可以正常工作,但没有它我就无法工作,因为我需要超过 50 Mo 的数据库。

编辑:我尝试这样做,但我也收到错误:myDb.allDocs({include_docs: false});

【问题讨论】:

标签: android sqlite cordova pouchdb


【解决方案1】:

您应该使用attachments,而不是直接将大的二进制字符串插入到您的文档中。这些将确保当您执行不接触附件的操作时(例如查询、allDocs() 等),PouchDB 不会将附件读入内存。这应该可以解决您的内存不足问题。

【讨论】:

  • 如何使用附件?可以举例说明吗
猜你喜欢
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
  • 2015-01-27
  • 2016-10-10
  • 2017-06-21
  • 2011-08-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多