Skip to content

Instantly share code, notes, and snippets.

@plepe

plepe/testfind.js

Created Mar 2, 2017
Embed
What would you like to do?
pouchdb-find error with elemMatch and array of objects
#!/usr/bin/env node
var async = require('async')
var PouchDB = require('pouchdb')
PouchDB.plugin(require('pouchdb-find'))
var db = PouchDB('foobar')
async.series([
// drop database and re-create (always start with new database)
function (callback) {
db.destroy(function (err) {
if (err) {
throw(err)
}
db = PouchDB('foobar')
callback()
})
},
// fill database
function (callback) {
async.parallel([
function (callback) {
db.put({ _id: "1", comments: [ { user: 'alice', date: '2017-01-01' }, { user: 'bob', date: '2017-01-02' } ] }, function (err) {
if (err) { throw(err) }
callback()
})
},
function () {
db.put({ _id: "2", comments: [ { user: 'alice', date: '2017-01-01' }, { user: 'charly', date: '2017-01-03' } ] }, function (err) {
if (err) { throw(err) }
callback()
})
}
],
function () {
callback()
})
},
// now query
function (callback) {
db.find({ selector: { 'comments': { '$elemMatch': { 'user': 'charly' }}}}, function (err, result) {
if (err) { throw(err) }
callback()
})
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.