4

I am working on a web application that uses mongodb as the database. Data is inserted into this db via a Java Application and i want to somehow monitor/understand that the data is inserted from a nodejs application so that i can push some information to the clients via socket.io.

I know this is quite easy when we remove Java part from the equation and carry out the insertion via nodejs. But this is not the case for me; so i need pointers on mongodb - nodejs push kind of a thing..

It would be very nice if the solution remains only with Java, Nodejs and mongodb. But if some other 3rd party framework or technology (like mq) must be included i would be happy to hear that.

4
  • There are various ways to watch Mongo data changes, like mongo-watch. Or you could simply have the Mongo DB operation also ping the Node app, etc. Commented Sep 24, 2014 at 19:15
  • @DaveNewton so is it possible to know from within nodejs app when java inserts data into mongodb Commented Sep 24, 2014 at 19:19
  • It is if (a) the Java app tells NodeJS, or (b) you're using a mongo watcher of some sort. Commented Sep 24, 2014 at 19:24
  • @DaveNewton thx for the info. I think i am going to try java - nodejs linking first. if that does not go well i might be using 3rd party watcher like mongo-watch. Commented Sep 24, 2014 at 19:29

2 Answers 2

3

I would suggest that you should look for apache kafka connect which provide source connector to keep watch on your mongo db. Confluent has created mongo connector which provide the above functionality. You can go through the above link for further research. Apache kafka is a messaging queue system.

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

Comments

2

I'd suggest having the Java App let your front end (node) app know when it has changed something. That leaves the responsibility of knowing what has changed and how with the system making the changes. Watching the DB for changes sounds like a good idea, and will likely work but it's far more likely to cause you issues. Consider:

  • What data to watch?
  • What changes do you consider worthy of action?
  • What happens when you change how your data is updated?
  • How do you know when a change is atomic?

All these issues are at least mitigated if your front end is simply told what has changed and how, where to get the resource and when it happend.

How you tell your front end is up to you. Simple HTTP calls from Java to your front end is simple, if a little unreliable and unpredictable (load wise). A queue/notification service like Amazon SNS might be a little more robust.

1 Comment

This is a late comment but i ended up POSTING the relevant data to Node.JS and then inserting to Mongo DB in an atomic process which is carried out by Java Application

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.