0

I can connect to mongodb by mongoose in nodejs as below.

mongoose.connect('mongodb://127.0.0.1:27017/something', dbOptions, err => {
  if(err) { return process.exit(1) }

  someSchema.findOne({}, result =>{
    if(!result) { someSchema.insert({some object}) }
    return process.exit(0)
  })
})

I can run this file on nodejs without problem.
But I want to run this file on lunux shell script. How can I make this concept on shell script? Could you give me some advice? Thank you so much for reading it.

Thomas Jason
  • 538
  • 2
  • 7
  • 18
  • https://stackoverflow.com/a/6000360/1497533 – ippi Aug 05 '20 at 03:26
  • Does this answer your question? [How to execute mongo commands through shell scripts?](https://stackoverflow.com/questions/4837673/how-to-execute-mongo-commands-through-shell-scripts) – D. SM Aug 05 '20 at 03:31
  • Another solution - Make a js file for this code and run in shell command using `node your-file.js` – Jagveer Singh Aug 05 '20 at 05:24

0 Answers0