Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Executing Stored Function with params
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
M.  
View profile  
 More options Nov 18 2011, 8:13 pm
From: "M." <minjae.hw...@gmail.com>
Date: Fri, 18 Nov 2011 17:13:38 -0800 (PST)
Local: Fri, Nov 18 2011 8:13 pm
Subject: Executing Stored Function with params
Hello,

I'm trying to execute a stored function like this from node.js.

    this.db.eval('identity', 100, function(err, doc) {
        console.log(doc);
    });

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.

Any idea?

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
christkv  
View profile  
 More options Dec 17 2011, 5:17 pm
From: christkv <chris...@gmail.com>
Date: Sat, 17 Dec 2011 14:17:37 -0800 (PST)
Local: Sat, Dec 17 2011 5:17 pm
Subject: Re: Executing Stored Function with params

examples of usage in

https://github.com/christkv/node-mongodb-native/blob/master/test/db_t...

but basically

client.eval('function (x, y) {return x + y;}', [2, 3], function(err,
result) {
  test.equal(5, result);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phill Rosen  
View profile  
 More options Sep 14 2012, 3:56 pm
From: Phill Rosen <phill.ro...@gmail.com>
Date: Fri, 14 Sep 2012 12:56:28 -0700 (PDT)
Local: Fri, Sep 14 2012 3:56 pm
Subject: Re: Executing Stored Function with params

Did you ever get this resolved? I am seeing issues with this currently.
Save database, same credentials.

From console I do:
db.system.js.save({ "_id" : "echo", "value" : function(x){return x;} })  

> db.eval("echo('test')")

test

However from the node driver:
db.eval("echo('test')", function (err, res) {
console.log(err);

}

Produces:
eval failed: invoke failed: JS Error: ReferenceError: echo is not defined
nofile... (length: 84)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
christkv  
View profile  
 More options Sep 16 2012, 11:07 pm
From: christkv <chris...@gmail.com>
Date: Sun, 16 Sep 2012 20:07:28 -0700 (PDT)
Local: Sun, Sep 16 2012 11:07 pm
Subject: Re: Executing Stored Function with params

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »