Im quite new to Javascript. i have a problem and i cant figure out what is wrong with my code. i have a function that should return a value from a mongoDB database. but it seems to return as empty every time. the function sites inside a JSON object like so:
getRecord: function (criteria) {
var record = {};
cats.findOne(criteria, function (err, results) {
if (err) console.log(err);
record = JSON.parse(JSON.stringify(results));
});
return record;
},
i have tried console.log inside the findOne function and it is logging what i expect to be returned, but the value seems to get destroyed outside the function.
im using "record = JSON.parse(JSON.stringify(results));" to try and create a brand new object (because i expect that the returned results from the DB would be deleting objects after the function has run).