Inside the database, there is identity function like this.
db.system.js.save(
{
_id : 'identity',
value : function (id) {
return id;
}
}
);
The result I want is 100 but it returns identity function itself. It
could be done something like db.eval('identity(100)', function(..)
{...})
However, I'd really love to pass parameters by object format, not by
textual representation.
> The result I want is 100 but it returns identity function itself. It > could be done something like db.eval('identity(100)', function(..) > {...}) > However, I'd really love to pass parameters by object format, not by > textual representation.
can you post a ticket with some code on github. I'll have a look during the week.
One big observation that will save you a lot of pain and suffering. Don't execute javascript on the server as part of you business logic it will seriously hamper your scalability. The reasons are very simple.
1. The javascript engine is single threaded (spidermonkey) 2. Eval will take out a write lock for the entire duration of the execution limiting your ability to scale writes.
I know it's tempting but javascript on mongodb was never designed to be mongodb stored procedures. The only valid reason is if you are using them during f.ex map-reduce jobs.
>> The result I want is 100 but it returns identity function itself. It >> could be done something like db.eval('identity(100)', function(..) >> {...}) >> However, I'd really love to pass parameters by object format, not by >> textual representation.