In couchdb I have a very simple map function so that I can lookup a list by tripid efficiently:

// by_tripid.js
function (doc) {

    if (doc.type == "list") {

        for (var tripid in doc.tripids) {
            emit(doc.tripids[tripid], null)
        } 
    }
}

The intention is to index the lists by tripid. And to be able to retrieve a list by tripid by specifying a key (the tripid).

In Pouchdb I can use roughly the same map function in the db.query call.

However, I don't want in effect to end up returning all the lists and then filtering them by tripid. That seems quite inefficient. I'm not sure about Pouchdb's view technology. The view is created and used at query time so I guess that Pouchdb isn't really applying the map to create an index. I suppose this is like a temp view in Couchdb so the efficiency isn't there perhaps.

Some expert opinion would be greatly appreciated.

Thanks, Matt

有帮助吗?

解决方案

There is an open issue on github to implement incremental views.

You are correct- right now PouchDB runs map-reduce on every document in the database, every time you call query, so performance is not great. For small databases this is fine, but obviously it's a problem for larger dbs.

其他提示

PouchDB's query interface supports passing options.key. It will be mentioned in the API docs next release.

  • If you are connecting to a remote couch it will pass the param to the remote view, and thus be optimized by couch itself.
  • For a local db, optimization is ongoing, but won't change the interface when it lands. Moral: just use the interface and don't worry about it unless you hit a performance wall.

Also of interest for quantifying the "how big is too big" question is the performance suite issue.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top