Post
Topic
Board Services
Re: ANSWER SIMPLE MONGODB QUESTION: GET 0.05 BITCOINS :) [closed I think we got it]
by
Lucky7Gaming
on 05/07/2016, 02:05:20 UTC
Alright, problem solved in a sketchy way.  Data is inputted this way:

Code:
function insertEvent(topic,payload) { 
  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
Code:
   "_id" : device01
   "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
Code:
var resultArray=[];
    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 Smiley  PM me your address (apparently btc is burning a hole in my hdd)