2

I'm very new to couchdb so my question may seem very simple; I'm using nano to connect to my couchdb; I have read most of the documentation, however I couldn't figure out how I can get all of the data in a table? What is the syntax to get all of the data of a table?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

2 Answers2

1

To get all the docs in a current database you'd request the /{db}/_all_docs endpoint.

Nano wraps that endpoint in two separate functions: listDoc and fetchDocs. See the code for nano.js. These functions are exported on the db object as list and fetch.

  • list will get you the ID's of all the docs in the database.
  • fetch will include the docs themselves in the result--which if you're building a backup system or similar is probably what you want.

Hope that helps!

BigBlueHat
  • 2,355
  • 25
  • 30
  • 1
    Also, forgot to mention that `nano` is now part of the Apache CouchDB project: https://github.com/apache/couchdb-nano That's the better one to use going forward--as it replaces the original, older one. – BigBlueHat Aug 28 '15 at 13:13
0

You may find this article useful.

To get all of the documents in a database, you can use the _all_docs API endpoint, which nano wraps in its' db.list method.

mydb.list(function(err, body) {
  if (!err) {
    body.rows.forEach(function(doc) {
      console.log(doc);
    });
  }
});
joewright
  • 325
  • 3
  • 7
  • Interesting; nano.db.list; lists all of tables, whereas foo.list lists all of the documents in foo table,... –  Aug 28 '15 at 13:10