使用nodeJS将时间序列更新到mongodb

时间:2018-03-20 06:04:16

标签: node.js mongodb

我希望以与本博客中提到的类似方式更新我的mongoDB以获取特定功能: https://www.mongodb.com/blog/post/schema-design-for-time-series-data-in-mongodb

以下是我希望数据库表格如下所示:

{
  _id : Object("5aab763d455a20153c05f024"),
  mapped_id : "5aaa21bdbf3dce44c41f1ba9",
  timestamp_hour: ISODate("2018-03-29T11:00:00.000Z"),
  type: “memory_used”,
  values: {
    0: { 0: 123, 15: 213, 30: 563, 45: 784},
    1: { 0: 134, 15: 632, 30: 489, 45: 893},
    …,
    58: { 0: 309, 15: 432, 30: 203, 45: 398},
    59: { 0: 123, 15: 209, 30: 290, 45: 432}
  }
}

我已经实现了以下内容:

var someFunction = function(){

var dateTime = new Date();
var values = {};
values[dateTime.getMinutes()] = {};
values[dateTime.getMinutes()][dateTime.getSeconds()] = "some random integer";

var myQuery = { mapped_id : DocumentID.toString() }; //some other Document in a collection.
var newValues = { $set : {values} };

}

setInterval(function(){

    someFunction();

}, 15000);

我只能得到这样的东西:

{
  _id : Object("5aab763d455a20153c05f024"),
  mapped_id : "5aaa21bdbf3dce44c41f1ba9",
  timestamp_hour: ISODate("2018-03-29T11:00:00.000Z"),
  type: “memory_used”,
  values: {
    58: { 15: 432}
  }
}

我只能获得一个对象值,它会在更新时更新为下一个值。

0 个答案:

没有答案