Hello,
I am using nodejs and mongoose. I am trying to do the equivalent of an "oracle stored procedure". The behavior I need is:
1. with some node.js javascript...
2. construct a script of, say, 50 lines.
3. send the the script to mongo
4. mongodb executes the script
5. mongodb returns the result
6. mongoose calls my node.js callback with the script result
Here is my attempt with a simple script:
-------------------
var script = "var l; l = db.somedb.somecollection.findOne({keyIndex: 'test'}); return { result: tojson(l) };";
mgoose.eval(script, (err, result) => {
console.log('TEST', err, util.inspect(result, {showHidden: false, depth: 99}));
doSomething(result);
});
--------------------
The code above returns { result: null } which seems odd to me.
Running the same script on the mongodb command prompt works as expected and returns a result.
What am I missing?
Thanks
Paul