Looking for a way to index pouchDB
Can\'t find a way to index when i have multiple dimensions
Here is my document client example
Note that client
As mentioned on CouchDB documentation:
... the
emit()
function can be called multiple times in the map function to create multiple entries in the view results from a single document...
Now we are going to use emit()
multiple times in the map function. Also we are going to emit arrays to have both invoiceNumber
and barCode
as the index, like this:
var myIndex = {
_id: '_design/my_index',
views: {
'my_index': {
map: function (doc) {
for(var i=0, length=doc.invoices.length; i
Now lets PUT
our above design document and query it with PouchDB:
pouch.put(myIndex).then(() => {
// query the index
return pouch.query('my_index', {key: ['12312313','1234324']});
}).then(result => {
// found docs with invoiceNumber === '12312313' and barCode === '1234324'
console.log('Result: ', result)
});
Also take a look at this similar answer.