New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query() defaults to reduce #7127

Closed
alxndrsn opened this Issue Mar 6, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@alxndrsn
Member

alxndrsn commented Mar 6, 2018

Issue

When calling db.query(), options.reduce: true defaults to true. According to the docs:

Defaults to false (no reduce).

Info

  • Environment: browser, Pouch 6.4.3
  • Platform: Chrome
  • Adapter: IndexedDB
  • Server: none

Reproduce

const db = new PouchDB('reduced-to-tears');

db
  .put({
    _id: '_design/mapred',
    views: {
      mapred: {
        map: function(doc) { emit(doc._id); }.toString(),
        reduce: function() { return 666; }.toString(),
      }
    }
  })

  .then(() => db.query('mapred'))
  .then(console.log)

  .then(() => db.query('mapred', { reduce:true }))
  .then(console.log)

  .then(() => db.query('mapred', { reduce:false }))
  .then(console.log)

  .catch(console.log);

->

screen shot 2018-03-06 at 09 29 49

Fix

IMO the documentation is correct, and the code should be fixed.

alxndrsn added a commit to medic/medic-webapp that referenced this issue Mar 6, 2018

Be explicit when querying a view with reduce
The PouchDB docs and implementation disagree whether options.reduce defaults to
true or false when querying a view which has both map and reduce functions
defined: pouchdb/pouchdb#7127

We should be explicit when calling a reduce because:

1. the current default (reduce: true) is non-obvious
2. if PouchDB fix 7127 by changing the implementation, then this commit will
   prevent our code from breaking.

@alxndrsn alxndrsn referenced this issue Mar 6, 2018

Closed

Be explicit when querying a view with reduce #4267

0 of 5 tasks complete
@janl

This comment has been minimized.

Contributor

janl commented Mar 6, 2018

The code mirrors couchdb's behaviour, which has been the guiding principle in the past. So I'd say we fix the docs :)

@alxndrsn

This comment has been minimized.

Member

alxndrsn commented Mar 6, 2018

I'd say we fix the docs

This is definitely consistent.

However, as neither PouchDB nor CouchDB allows a design document with a reduce function but no map function, I'd say that CouchDB's default is non-obvious and this is an opportunity for PouchDB to improve on that.

@daleharvey

This comment has been minimized.

Member

daleharvey commented Mar 12, 2018

I think when Couch is obviously wrong (like changing continious to live) we can break compatibility to improve, however map reduce is fairly non obvious in the first place so I think keeping compat and fixing the docs is the right thing here, we can hopefully just replace it all with find anyway :)

daleharvey added a commit that referenced this issue Mar 12, 2018

@daleharvey daleharvey closed this Mar 12, 2018

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