PouchDB query with exact 'key' and multiple results
HTML
<script src="//cdn.jsdelivr.net/pouchdb/3.0.6/pouchdb.js"></script>
<script src="https://github.com/pouchdb/pouchdb/releases/download/3.0.6/pouchdb.memory.js"></script>
<div id="logger"></div>
CSS
#logger { font-family: monospace }
JavaScript
var log = function (x) {
x = JSON.stringify(x)
document.getElementById('logger').innerHTML += x + "<br>"
}
var pouch = PouchDB('test', {adapter: 'memory'})
pouch.on('error', log)
pouch.bulkDocs([
{user: 'a', type: '2', name: 'contact/bob'},
{user: 'c', name: 'contact/bob'},
{user: 'b', type: '4', name: 'contact/bob'},
{user: 'd', type: '2', name: 'contact/bob'},
{user: 'a', name: 'contact/bob'},
{user: 'b', type: '2', name: 'contact/bob'},
{user: 'a', type: '2', name: 'contact/bob'},
{user: 'a', type: '2', name: 'contact/sam'}
])
pouch.query(function (doc, emit) {
emit([doc.user, doc.name, doc.type])
}, {
startkey: [null, 'contact/bob'],
endkey: ['\ufff0', 'contact/bob', '\ufff0']
}).then(function (res) {
if (res.rows.length === 0) {
document.getElementById('logger').innerHTML += 'no results'
}
res.rows.forEach(log)
})