I am on the client side of a websocket API which uses SocketCluster for its pub/sub.
After authenticating I receive every second json data via
SCsocket.on('authenticate', function(){
var channel = SCsocket.subscribe('channel1');
channel.watch(function(data){
console.log(data);
});
});
of the form
[
{
"product": "Product1",
"price": "10.0"
},
{
"product": "Product2",
"price": "15.0"
}
]
Instead of printing the data, I will save it to a mongo db.
In case some of the data cannot be uploaded, I need some sort of a safety net. Something that allows me to upload the data from the websocket to mongo db in retrospect.
What are best practices for doing that? I hope this question is not too broad, I am new to node and mongo db.
Thanks!
This is an example of how you can handle the data and save it into Mongo. I didn't have a mongo server running, so you'll have to check that the saving actually works. But the principle is there.
Not sure what you mean by safety net but I added in a check to see if the data is defined, you should more checks in there for your own specific cases.
Let me know if you need any help with something specific.