0

I am trying to run couple of Mongo scripts automatically after MongoDB server start.

I tried looking into various options in mongod.conf , but did'nt find any solution.

Could you please help me.

Software used:

MongoDB Community version 4.0.8

Windows 7 64 bit

4
  • What do you mean? You want some JavaScript code to run in the mongo shell as soon as a server is up and running? If so then what sort of things do you think are important to run as soon as a server instance starts? Or what exactly is your question? "I want to run a couple of scripts..." is really not that clear. Commented Apr 4, 2019 at 9:33
  • @NeilLunn Yea I need to run JavaScript code for inserting a document. This script must run automatically after the server start/restart. Commented Apr 4, 2019 at 9:40
  • I suggest you be a bit more clear about what you think you need to do in your question. Chances are you really don't need to do what you "think" you need to do. Or at least there should be no dependency on "server starting". You probably actually mean "seed some data for my application", and that's actually a completely different thing to how your question comes across. Basically if you cannot string at least two paragraphs or even better an "example" of what you need to achieve, then it's an unclear question. Two Sentences does not convey your intent. Commented Apr 4, 2019 at 9:47
  • How are you starting mongDB and what is the script you need to run, please provide these details to understand? Commented Apr 4, 2019 at 10:07

1 Answer 1

1

Unfortunately MongoDB does not have any support for triggers.
As other people have commented if you have a certain schedule you can work around that.

You can also try and use other services like Mongo Stich where there's no real trigger like server restart but you can work around it with binding a trigger to an event like first insert or first login.

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

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.