GithubHelp home page GithubHelp logo

Support params on bulk_docs about nano HOT 9 CLOSED

apache avatar apache commented on August 27, 2024
Support params on bulk_docs

from nano.

Comments (9)

PatrickHeneise avatar PatrickHeneise commented on August 27, 2024

You can use db.list() with an array of ids:

  db.list {keys: doc_keys, include_docs: true}, (error, data) ->

from nano.

InTheFiveByFive avatar InTheFiveByFive commented on August 27, 2024

See my commit @ https://github.com/InTheFiveByFive/nano/commit/a96a50d2e1fd52ca69ca70bea6163e4445bd7c88

from nano.

PatrickHeneise avatar PatrickHeneise commented on August 27, 2024

You're using POST which is supposed to send data to the database, not GET something. Also, as mentioned, the function already exists, you just need to add {include_docs: true} as parameter:

function list_docs(params,callback) {
      if(typeof params === "function") {
        callback = params;
        params   = {};
      }
      return relax({db: db_name, path: "_all_docs", method: "GET", params: params},callback);
    }

from nano.

InTheFiveByFive avatar InTheFiveByFive commented on August 27, 2024

Per the bulk document api (http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API),

By POSTing to _all_docs you can get a set of documents with arbitrary keys

Simple example to fetch the keys bar and baz and include the complete document in the result set:

curl -d '{"keys":["bar","baz"]}' -X POST http://127.0.0.1:5984/foo/_all_docs?include_docs=true

db.list() will return all documents, not a subset. To retrieve a subset of documents you POST with the body set to the list of keys.

from nano.

dscape avatar dscape commented on August 27, 2024

Hi @InTheFiveByFive

I'm currently away at a conference with limited time so can't follow up right now. If you can prepare a pull request I can check it out. If not just give me 1/2 days to review this and put in in npm. if this is a bug, i havent looked at it yet :)

from nano.

dscape avatar dscape commented on August 27, 2024

Ok, I couldn't stop myself from reading this

@InTheFiveByFive please submit a pull request doing:

Minimal: function bulk_docs(docs,callback) -> function bulk_docs(docs, params, callback)

just if typeof params === function and preserve existing api behavior. so this should break any existing production nano code. am i missing something here?

if this is the case ill accept a pull request and publish to npm.

thanks for submiting this issue and working on this. we are always super excited to have more people invested in our little community. feel free to add your projects and community to our wiki :)

from nano.

PatrickHeneise avatar PatrickHeneise commented on August 27, 2024

Hmm, "keys" is not the same as "startkey" and "endkey", it does indeed return a subset with only the documents requested by key, so it's the same behavior as POSTing the keys in the body. However, I can't find that in the API, so I suppose it's better to use POST.

from nano.

dscape avatar dscape commented on August 27, 2024

@InTheFiveByFive any updates on this or did this ended up not being necessary?

from nano.

InTheFiveByFive avatar InTheFiveByFive commented on August 27, 2024

FYI, after testing the changes in my application, this issue is not fixed. It turns out the the bulk read api uses POST _all_docs path whereas the bulk write api uses the POST _bulk_docs path.

So for multiple downloads by key, list_docs() has the right path but the wrong verb and bulk_docs() has the right verb and the wrong path.

I'd propose we go with the original design of adding a new method to expose POST _all_docs. No need to revert pull request #54, as it just added params support which might be useful in other scenarios.

from nano.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.