I want to print out only the countries name and their population.
I have assorted them in ascending order and would like to print out only their names and populations in that order. When I try to do that I get "undefined".
When I print my function, I get the whole list but in an array.
const DataStore = require('nedb');
const db = new DataStore({filename: __dirname + '/countriesDB', autoload: true});
db.ensureIndex({ fieldName: 'country', unique: true }, function (err) {});
db.find({country: /^M/}).sort({ population: 1 }).exec(function (err, docs) {
if (err) {
console.log("something is wrong");
} else {
console.log("Name " + db.country + ", Population: " + db.population);
console.log(docs);
}
});
I get this with my current code:
Name undefined, Population: undefined
[ { country: 'Micronesia, Federated States of',
abbreviation: 'FM',
_id: 'yISdEnQoml9dJEpL',
city: 'Palikir',
dish: null,
location: 'Micronesia',
population: null },
{ country: 'Montserrat',
abbreviation: 'MS',
_id: '0GAqvRD9FbZRVvE3',
city: 'Plymouth',
dish: null,
location: 'Caribbean',
population: 11000,
area: 102 },
I want to see something like:
Name: Micronesia, Federated States of, Population: null
Name: Montserrat, Population: 11000