I am trying to create a method that will fetch a record from a collection based on a parameter and a value something like.
where parm is for instance the _id field in this schema.
getRecord('_id', '1234567876543')
getRecord(parm, value){
db.collection.findOne( { parm : value } , function(err, item) {
if (err) {
console.error(err);
}else if (item === null ) {
console.error('record does not exist');
}else {
Record = JSON.stringify(item);
}
});
}
What is happening is that this code is trying to fetch the colum parm from the table which does not exist, returning record does not exist every time.
How can I pass the value of the param in the findOne Query?