var key=topic.replace(deviceRoot,'');
console.log(payload);
collection.update(
{ _id:key },
{ $push: { value:String(payload), when:new Date() } },
{ upsert:true },
function(err,docs) {
if(err) { console.log("Insert fail"); } // Improve error handling
}
)
}
which gives
"temp" :[ 33.2,
34
]
"when" : [
ISODate("2016-07-05T01:42:38.314Z"),
ISODate("2016-07-05T01:42:43.631Z"),
ISODate("2016-07-05T01:42:48.964Z"),
}
which can be used sketchily with
mongo.connect(url, function(err, db) {
var cursor = db.collection('test_mqtt').find({"_id":"arduino01"},{"value":1,"_id":0});
cursor.forEach(function(doc, err) {
resultArray.push(doc.value);
}, function() {
db.close();
console.log(resultArray[0]);
but Lavender, I'll tip for pointing me in the right direction by saying it was impossible PM me your address (apparently btc is burning a hole in my hdd)