marcello3d / node-mongolian

[project inactive] Mongolian DeadBeef is an awesome Mongo DB driver for node.js
https://groups.google.com/group/node-mongolian
zlib License
350 stars 50 forks source link

Question: How do I use eval() with mongolian ? #12

Closed qharlie closed 13 years ago

qharlie commented 13 years ago

I need to execute some server side functions, how can I do this ?

marcello3d commented 13 years ago

It's not yet implemented.

marcello3d commented 13 years ago

Added in b0d6b9d820a23759dae7, but not tested.

Please add some unit tests!

qharlie commented 13 years ago

Ok, will add some unit tests now :).

qharlie commented 13 years ago

There is a an error in line 170 of lib/db.js:

Should be change to : this.queryCommand(command, callback)

qharlie commented 13 years ago

I'm also unsure how to pass arguments.

If I pass them as a list like the mongodb native driver does it, like this

db.eval( function ( x, y ) { return x; } , [ 2, 3 ] , function ( err, value) { console.log(value); });

I get , { retval: [ 2, 3 ], ok: 1 }, so X is actually a list of [2,3 ].

If I pass them like this,

db.eval( function ( x, y ) { return x; } , 2, 3 , function ( err, value) { console.log(err); });

which is what the mongolian code looks like it expects, I get: { stack: [Getter/Setter], arguments: undefined, type: undefined, message: 'Server Error: { \'$err\': \'BSONElement: bad type 49\', code: 10320 }', result: { '$err': 'BSONElement: bad type 49', code: 10320 } } 30 Apr 01:05:55 - [Log] - { '0': [] }

How should I be passing parameters ? After this is fixed I'll add some vows.

marcello3d commented 13 years ago

Your second example is right. But I had forgotten that manipulating arguments changes the values in the arguments array. I committed a fix for that error and some super simple tests based on your examples.