Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
inconsistent_results_couchdb_reduce_error.js
it('should handle user errors in reduce functions', function () {
return new Pouch(dbName).then(function (db) {
function getKey(row) {return row.key; }
db.on('error', function () { /* noop */ });
return createView(db, {
map : function (doc) {
emit(doc.name, doc.data);
},
reduce : function (keys, values) {
return values[0].foo.bar;
}
}).then(function (queryFun) {
var docs = [
{name: 'arb', _id: '0', data: {foo: {bar: 2}}},
{name: 'bar', _id: '1', data: 'quux'},
{name: 'bar', _id: '2', data: {foo: {bar: 1}}},
{name: 'baz', _id: '3', data: 'quux'}
];
return db.bulkDocs({docs: docs}).then(function () {
return db.query(queryFun, {group: true});
}).then(function (res) {
res.rows.map(getKey).should.deep.equal(['arb', 'bar', 'bar', 'baz']);
return db.query(queryFun, {reduce: false});
}).then(function (res) {
res.rows.map(getKey).should.deep.equal(['arb', 'bar', 'bar', 'baz']);
});
});
});
});
@nolanlawson

This comment has been minimized.

Copy link
Owner Author

@nolanlawson nolanlawson commented Apr 10, 2014

Occasionally the keys are ['arb', 'bar', 'bar', 'baz'], occasionally they are ['arb', 'bar', 'baz'].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment