Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Some question... #316

Open
ghost opened this issue Mar 16, 2016 · 1 comment
Open

Some question... #316

ghost opened this issue Mar 16, 2016 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 16, 2016

I wanted to get [{id: 'apples', name: 'Apples'}, {id: 'pears', name: 'Pears'}] as output, but I get [] as output.

I added the documents to the database with Futon like this:

This is my code:

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

var categories = nano.db.use('categories');

var listCategories = callback => {
  if (callback) {
    categories.list(function(err, body) {
      if (!err) {
        var toReturn = [];
        body.rows.forEach(function(doc) {
          toReturn.push(doc.id);
        });
        callback(toReturn);
      }
    });
  }
};

var getCategoryName = (category, callback) => {
  if (category && callback) {
    categories.get(category, {revs_info: false}, function(err, body) {
      if (!err) {
        callback(body.name);
      }
    });
  }
};

var listCategoriesWithNames = callback => {
  if (callback) {
    listCategories(function(cats) {
      var toReturn = [];
      cats.forEach(function(cat) {
        getCategoryName(cat, function(name) {
          var temp = {};
          temp[cat] = name;
          toReturn.push(temp);
        });
      });
      callback(toReturn);
    })
  }
};

listCategoriesWithNames(function(returned) {
  console.log(returned);
});

So, how do I get the desired output?

@carlosduclos
Copy link

This repository has been merged into apache/couchdb-nano, please continue the discussion here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant