I don't know why, but for some reasons I have trouble getting data from my indexedDB using PouchDB and storing that data in a variable.
I have a function that fetches all the data from my database, like this:
load_all = function() {
var database = new PouchDB('ProjectDB');
var remoteCouch = false;
database.allDocs({include_docs: true, descending: true}, function(error, doc) {
if (error) ...
else {
if (doc.rows.length > 0) return doc.rows;
else ...
}
});
}
var projects = load_all();
console.log(projects); // will log 'undefined'
I have no idea why it wont, work.