1

I have a pouch database that contains hundreds documents of 1 Mo, so the total size is ~100 Mo. It's an Android Cordova app and I'm using:

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

Each document is like this:

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

I'd like to do a query on this db to list all documents indexed by filename and index, without retrieving data property which is heavy.

So I did a view like this:

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

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

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

myDb.put(designDoc);

But when I try to query my db, like this:

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

I get the following error:

error

Why I'm having this error ? I still have 900 Mo of ram available on my device (Android 6), and I'm not even including docs. If my db is less than 20 Mo it works fine.

It was working fine too with db of 40 Mo before using SQLite plugin, but I can't work without it since I need more than 50 Mo database.

Edit: I tried to do this and I get the error too: myDb.allDocs({include_docs: false});

sylvain1264
  • 825
  • 1
  • 8
  • 21
  • May provide some guidance: http://stackoverflow.com/questions/32244851/androidjava-lang-outofmemoryerror-failed-to-allocate-a-23970828-byte-allocatio – Jay Gould Jul 13 '16 at 15:30

1 Answers1

2

Instead of directly inserting large binary strings into your documents, you should use attachments. These will ensure that when you do operations that don't touch attachments (such as queries, allDocs(), etc.), PouchDB won't read the attachments into memory. This should fix your Out Of Memory issues.

nlawson
  • 11,050
  • 3
  • 35
  • 47