Created
March 2, 2017 21:02
-
-
Save plepe/44c5f2dfd210c695b4cb4ddb6b254ec8 to your computer and use it in GitHub Desktop.
pouchdb-find error with elemMatch and array of objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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