Q:

Most performant way of range querying large PouchDB datasets

I'm building an IoT application which collects a bunch of different metrics every second. On the client I'm displaying the data using charts.
However, every time I change the time range of the charts/reload the page, it takes waaay too long to load all datapoints from the server. So I've started looking in to persistent storage in the browser, mainly using PouchDB. Then every time the browser refreshes, the data fetching will be much snappier. Of course you have to take Browser Quota etc into consideration, but that is a different issue.
An example datapoint looks like this
{
   "metricId": <String>,
   "metricName": <String>,
   "timestamp": <Unix Timestamp>
   "value": <Integer>
}

Approach 1 - Multiple databases, one index
As I have many different metrics, I'm thinking of creating a new PouchDB database per metric, and then index on the timestamp.
// (using pouchdb-find plugin)
const db = new PouchDB(<metricName>);
db.createIndex({ index: { fields: ['timestamp'] } })
db.find({ 
    selector: { timestamp: { '$gte' : from, '$lte' : to }}
})

Approach 2 - One database, multiple indices
The other solution is to create one database to hold all the metrics, and have multiple indices instead.
// (using pouchdb-find plugin)
const db = new PouchDB('all_data');
db.createIndex({ 
    index: { fields: ['metricId', 'metricName', 'timestamp'] } 
});
db.find({ 
    selector: { 
        $and: [
            { metricId: metricId }, 
            { metricName: metricName },
            { timestamp: { '$gte' : from, '$lte' : to }}
        ]
    }
})

Question
Which is the most performant on the two, or is there a smarter way of creating the indices? Or is there a different approach without using PouchDB at all?

A:

Anwering my own question as I found a solution, not using PouchDB but using YDN-DB. Using Approach 1 above with multiple databases and one indexed column (of type integer timestamp), I've reached very good performance.
Both writing and reading ~5000 rows takes about 300 ms. My tests showed that this approach is about 3x faster than using a compound index (Approach 2).
Posting code here if anyone else stumbles upon this SO question.
// Create unique DB with index
const dbname = [metricId, metricName].join("_");
const schema = {
    stores: [{
        name: 'metrics',
        indexes: [{ keyPath: 'timestamp' }]
    }]
}
const db = new ydn.db.Storage(dbname, schema);

// writing data.. timestamp is unix timestamp
db.put('metrics', { timestamp, value }, timestamp);

// reading data
const query = db.from('metrics').where('timestamp', '>=', from, '<=', to);
query.list(5000).done(result => {
    console.log(result);
});

