Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Running arbitrary MongoDB scripts through Node.js driver

Running arbitrary MongoDB scripts through Node.js driver

Problem

I have a combination of complex MongoDB scripts that runs from the command line as follows:

$ mongo mydb config.js task.js

Since I can't run shell scripts in my server environment and need to schedule the above task, I figured I could simply concatenate the above .js files and then run them from a Node script. Hence I am looking for an equavalent to:

db.runMyCustomRawCommands(string commands)

How can I do this, or what would be an alternative solution?

Problem courtesy of: Sam

Solution

To quote Christian Kvalheim, original author of the Node.js native MongoDB driver:

that's not possible as the shell is synchronous and have different apis than the node.js driver. you would have to rewrite the scripts to work for node.js.

Solution courtesy of: Sam

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Running arbitrary MongoDB scripts through Node.js driver

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×