2

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

where does this quote come from? can you share the link?
I emailed him directly.
1

The problem is that db.runMyCustomRawCommands is not a raw command. The drivers communicate with the mongod server on a lower level. Commands such as db.abc you run in the console are actually simple query messages referencing the db.$cmd collection as db.$cmd.findOne({ abc: 1 }) or similarly.

You thus have to either figure out how to express your mongo shell script as calls to your driver's API or access the server on a lower level.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.