Particle.publish format for Mongodb?


I set up Node Red in an IBM Bluemix free account to receive my published data and store it into a free Mongodb. This works very reliable and I found all information in this forum to set everything up :smile:

Now my question is how to format the publish string so it gets stored in the right format in my Mongodb.

My code:

String dataString = String( "{ \"temp\":" + String(temp) + ",\"hum\":" + String(hum) + ",\"light\":" + String(light)+"}");

Spark.publish("Sensordata", dataString, 60, PRIVATE);

Or is it necessary to parse the data in a function node in Node Red? My aim is to store the data in a way I can easily build graphs and process it further.

Then you should probably parse and reconfigure the data before storing it. The ‘bucket’ approach is recommend for time series data. Create a ‘hour’ document in mongoDB, and fill it with empty ‘minutes’ data. When the data comes in, overwrite the empty spaces. Not only is it quicker, it also makes sure the data doesn’t have to be relocated as the file grows. Even better, your data is easier to retrieve later on, since much less documents are created. Finding a specific time frame is thus much quicker.
Rather than me paraphrasing the whole thing, do a Google search for ‘Mongo time series’, and browse around a bit.

Thank you very much for your answer! :slight_smile: I hope I can find some tutorials too as I am a database noob :grin:

I also found influxdb but I could not find any small free account. All offers are limited to a few days :frowning: