1

I have an nodejs server running witch show data on a web interface. The data is fetched from a MongoDB using mongoose. The data is added via an node-red application witch is isolated from the rest.

Currently my nodejs server fetches the data every 5 seconds. Is there a way to know if the data in my MongoDB has changed?

Thanks, I hope my question is clear.

Jan
  • 560
  • 6
  • 19

1 Answers1

2

I was also looking for something similar to what you are asking for few months back. Few ways which i know to do it are:

1) You can try to use middlewares while inserting your documents in DB. You can then send that new data either after saving it in DB or at the time of insertion only.

2) Refer to this answer which talks about solving your problem using inbuilt functions provided by mongoDb. You can study in deep about them in mongoDb docs.

3) There is also another way to do this which includes listening to changes in log files. As you know everything done in mongo is recorded and logged in files so whenever there is some change in data you can know it from there also. You will have to do the digging by yourself in this method.

Hope it helps!

Community
  • 1
  • 1
node_saini
  • 727
  • 1
  • 6
  • 22