Skip to main content
Solved

Groovy establish connection to mongodb

  • January 13, 2022
  • 3 replies
  • 324 views

Jagadeesh
Fan

HI,

Could you please provide a snippet of connection establish to mongodb from groovy script.

 

 

Best answer by dima

If you want to do this once per pipeline run, I'd simply use the Pipeline Start event to call a Shell executor and have the mongo shell drop your collection for you (you'd just need to have that installed on your Data Collector node). Seems a lot easier than dealing with packages and Groovy code.

View original
Did this topic help you find an answer to your question?

3 replies

dima
StreamSets Employee
Forum|alt.badge.img
  • StreamSets Employee
  • 83 replies
  • January 13, 2022

Any reason not to just use one of the existing MongoDB stages? What's your use case?


Jagadeesh
Fan
  • Author
  • Fan
  • 1 reply
  • January 13, 2022

Use Case : i should drop the existing collection before loading the new collection.I though of using groovy script to handle in mongodb (drop & create collection) it is truncate & load scenario.


dima
StreamSets Employee
Forum|alt.badge.img
  • StreamSets Employee
  • 83 replies
  • Answer
  • January 13, 2022

If you want to do this once per pipeline run, I'd simply use the Pipeline Start event to call a Shell executor and have the mongo shell drop your collection for you (you'd just need to have that installed on your Data Collector node). Seems a lot easier than dealing with packages and Groovy code.


Reply