Open ghost opened 8 years ago
I wanted to get [{id: 'apples', name: 'Apples'}, {id: 'pears', name: 'Pears'}] as output, but I get [] as output.
[{id: 'apples', name: 'Apples'}, {id: 'pears', name: 'Pears'}]
[]
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?
This repository has been merged into apache/couchdb-nano, please continue the discussion here
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:
So, how do I get the desired output?