node.js - Upserting element of array in a timeseries array -


i'm following schema design document mongodb @ https://www.mongodb.com/blog/post/schema-design-for-time-series-data-in-mongodb

for time series model:

{   timestamp_hour: isodate("2013-10-10t23:00:00.000z"),   type: “memory_used”,   values: {     0: { 0: 999999, 1: 999999, …, 59: 1000000 },     1: { 0: 2000000, 1: 2000000, …, 59: 1000000 },     …,     58: { 0: 1600000, 1: 1200000, …, 59: 1100000 },     59: { 0: 1300000, 1: 1400000, …, 59: 1500000 }   } } 

the tutorial uses $set change values:

db.metrics.update(   {      timestamp_hour: isodate("2013-10-10t23:00:00.000z"),     type: “memory_used”   },    {$set: {“values.59.59”: 2000000 } } ) 

in practice, values added @ interval, this:

{   timestamp_hour: isodate("2013-10-10t23:00:00.000z"),   type: “memory_used”,   values: {     0: { 0: 999999, 1: 999999, …, 59: 1000000 },     1: { 0: 2000000, 1: 2000000, 2: 1900000 }   } } 

the question have when trying insert "values.1.3:2000000" in next slot dynamically. code wouldn't know 1 , 3 directly, parse out minutes , hours values date() , put them variables. doesn't work because overwrites "values" entirely:

var arry_t = {h:date.gethours(), m:date.getminutes()}; var m = {}; m[arry_t.m] = 2000000; var h_t = {}; h_t[arry_t.h] = m; console.log("h_t: ", h_t); // outputs {1: {3: "2000000"}}  db.metrics.update(    {type: “memory_used”,},     { $set:         {             value: h_t //this doesn't work since overwrite value         }    },     { upsert: true },    function(err,docs) {    if(err) {       console.log("insert fail")      }     }  ); 

how can code dynamically upsert next value array?


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -