Nugget Post: Pouchdb-find regex example

Here’s an example of using the excellent pouchdb-find plugin’s (https://github.com/nolanlawson/pouchdb-find) regex features. I couldn’t really find a good example in the documentation, but looking at the source code we come up with something like this:

db.find({
selector: {
_id: {$gte: null},
name: {$regex: ".*ri.*"}
},
fields: ['_id', 'debut', 'name', 'series']
});

Note that the $regex command cannot be run on an indexed field, so this will be a slow query – apart from the expensive regex operation, all records are being loaded into memory and scanned.

The above example can be run on the pouchdb-find demo site (http://nolanlawson.github.io/pouchdb-find/)