Get some CouchDB documents.



  • How do you get some papers through nano?

    For example, the following documents are based

    {
      total_rows: 3,
      offset: 0,
      rows: [
        {
          id: "https://github.com/dscape/nano",
          key: 2015
        },
        {
          id: "https://ru.wikipedia.org/wiki/",
          key: 2015
        },
        {
          id: "https://ru.wikipedia.org",
          key: 2015
        },
        {
          id: "https://ru.wikipedia.org/kill",
          key: 2016
        }
      ]
    }
    

    by function (approximately):

    likes.list([
      "https://github.com/dscape/nano",
      "https://ru.wikipedia.org/wiki/"
    ],function(err, body) {
      body.rows.forEach(function(doc) {
        console.log(doc);
      });
    });
    

    Get out.

    {
      total_rows: 2,
      offset: 0,
      rows: [
        {
          id: "https://github.com/dscape/nano",
          key: 2015
        },
        {
          id: "https://ru.wikipedia.org/wiki/",
          key: 2015
        }
      ]
    }
    


  • There is a special API method for a sample of several documents from their key collection in CouchDB http://docs.couchdb.org/en/1.6.1/api/database/bulk-api.html#post--db-_all_docs ♪ The HTTP request in this case shall be:

    POST /db/_all_docs?include_docs=true HTTP/1.1
    Accept: application/json
    Content-Length: 51
    Content-Type: application/json
    Host: localhost:5984
    

    {
    "keys" : [
    "asd",
    "qwe"
    ]
    }

    In nano, the method is used. https://github.com/dscape/nano#dbfetchdocnames-params-callback :

    var db = require('nano')('http://localhost:5984/db');

    db.fetch(['asd', 'qwe'], function(err, data) {
    // ...
    });




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2