I want to perform a find query to MongoDB to check whether a particular entry is in DB or not. But it calls a callback function which is asynchronous. How can I get the result?
In this I am not getting the actual result synchronously.
I want to perform a find query to MongoDB to check whether a particular entry is in DB or not. But it calls a callback function which is asynchronous. How can I get the result?
In this I am not getting the actual result synchronously.
If you are using Node.js you ought to do it the asynchronous way.
Example:
db_call(query, function (err, result) {
if (err) { throw new Error('db_error'); return; }
console.log(result); // do your stuff here
});