You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/04/14 10:27:10 UTC

[GitHub] [couchdb-nano] kozlovzxc opened a new issue #263: Fields param is missing for changesreader.get

kozlovzxc opened a new issue #263:
URL: https://github.com/apache/couchdb-nano/issues/263


   ## Expected Behavior
   
   [The CouchDB documentation](https://docs.couchdb.org/en/stable/api/database/changes.html#selector) describes that it is possible to provide _selector for `_chages` handler
   ```
   POST /recipes/_changes?filter=_selector HTTP/1.1
   Content-Type: application/json
   Host: localhost:5984
   
   {
       "selector": { "_id": { "$regex": "^_design/" } }
   }
   ```
   
   [The documentation also describes](https://docs.couchdb.org/en/stable/api/database/find.html#filtering-fields) that selector can contain a list of specified fields to filter.
   
   ```
   {
       "selector": { "Actor_name": "Robert De Niro" },
       "fields": ["Actor_name", "Movie_year", "_id", "_rev"]
   }
   ```
   
   ## Current Behavior
   
   Right now it is only possible to provide the `selector` parameter, but not the `fields` parameter. [Link](https://github.com/apache/couchdb-nano/blob/c84d0a43b13edc888a2a339f7fb057ad66d3d3fe/lib/changesreader.js#L168)
   ```
             if (self.selector) {
               req.qs.filter = '_selector'
               req.body.selector = self.selector
             }
   ```
   
   ## Possible Solution
   
   Locally I've fixed it just by adding another parameter. It can be something like this:
   ```
             if (self.selector || self.fields) {
               req.qs.filter = '_selector'
               req.body.selector = self.selector
               req.body.fields = self.fields
             }
   ```
   
   It also may worth adding another custom `body` param similar to `qs`, which adds additional body params. 
   ```
             Object.assign(req.qs, opts.qs)
             // New
             Object.assign(req.body, opts.body)
   ```
   
   ## Steps to Reproduce (for bugs)
   
   It should be straightforward to reproduce, but I can add exact steps if needed.
   
   ## Context
   
   I was trying to fetch few fields from https://replicate.npmjs.com, but I didn't need all extra fields as versions, because it noticeably slows the script down and increases network consumption.
   
   [More context](https://github.com/npm/registry/blob/master/docs/REPLICATE-API.md)
   
   ## Your Environment
   * Version used:   `"nano": "^9.0.3",`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org