I'd like to pass a string like "db.users.find()" to the node server and have it execute the command. This question: How to execute a MongoDB query in the native node-mongo-native driver? has an answer for the C- driver.
Is there a way to do it directly with the native node driver? I've tried doing
db.eval('function(){'+query+'}', function(err, result){
console.log("the result is", result
});
and it doesn't work. Appreciate the help.
You're close, but the function you create needs to return something usable to the callback. For example:
var query = 'db.users.find()';
db.eval('function(){ return ' + query + '.toArray(); }', function(err, result){
console.log("the result is", result);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With