Stored Procedures mongoose

266 views
Skip to first unread message

Paul Sheer

unread,
Jun 15, 2017, 5:33:00 PM6/15/17
to Mongoose Node.JS ODM

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

Paul Sheer

unread,
Jun 19, 2017, 11:08:15 AM6/19/17
to Mongoose Node.JS ODM


Seems mongoose stores collections as follows:

If your collection is named somedb.MyCollection, then it puts it in lowercase, moves it to the top level, and adds an 's' as follows:

   db.mycoollections.find()

But doing db.somedb.MyCollection.find() will return nothing.

It works now.

Paul
Reply all
Reply to author
Forward
0 new messages