I have a MongoDB
database, Node.js
server and User Interface.
The connection between the three is working and data is being sent between them.
I am creating a real-time web application and I am using a setTimeout()
feature to request data from database via the client's webpage every 4 seconds.
BUT the data that is coming back is the same everytime and isnt updating from the database. It is acting as if there is only one MongoDB session and just sending the same set of data that is collected from when the server starts.
On the Node.js
server code, I made sure that a connection is opened and close once the query has completed but it is collecting the same set of data every time and no new data that has come into the database. The only way I can get it to update the data from the database is to turn the server on and off to reconnect to the database.
Would using some thing like socket.io
be better for the real time requests or is it possible to do real time data just with a setTimeout()
feature on the client side and normal MongoDB
collection queries?
Is there a way to constantly refresh the connection to the database?