Another question - response object
biomade opened this issue · 2 comments
biomade commented
I can now query my little db and so how do I access the value pairs.
Here is what is in the authors table
{"id":1,"name":"laurie","email":"laurie@gmail.com"}
{"id":2,"name":"erich","email":"erich@gmail.com"}
Here is my code
var dbauthors = db.load('db/authors.nosql');
//insert two records
//dbauthors.insert({ id: 1, name: 'laurie', email: 'laurie@gmail.com'} )
//dbauthors.insert({ id: 2, name: 'erich', email: 'erich@gmail.com' })
//console.log("inserted two records in authors");
//now find the second author
dbauthors.find().make(function(builder) {
builder.where('id', 2);
builder.callback(function(err, response) {
console.log('users between 2 and 4:', response);
console.log('users email:', response.email)
});
});
And what I get in the console.
users between 2 : [ { id: 2, name: 'erich', email: 'erich@gmail.com' } ]
users email: undefined
petersirka commented
dbauthors.find().make(function(builder) {
builder.where('id', 2);
builder.first(); // nosql returns only the first item (so in the response won't be an array)
builder.callback(function(err, response) {
console.log('users between 2 and 4:', response);
// because response was array
console.log('users email:', response.email)
});
});
biomade commented
Thanks so much for your help. I will add this to my testing code.