简体   繁体   English

使用nodejs将实时数据记录到mongodb

[英]record realtime data to mongodb using nodejs

How I can pick JSON.stringify and post to my mongoDB Database? 如何选择JSON.stringify并将其发布到mongoDB数据库?

For Exemple: 举个例子:

import express from 'express';

let data_record = JSON.stringify({**any content**})

This code will automatically receive data every 60 seconds and I want post this data to my DB. 该代码将每60秒自动接收一次数据,我想将此数据发布到我的数据库中。

I set the route like below: 我将路线设置如下:

app.post('/recording/ttn', (req, res) => {
  res.send(data_record);
});

Do you have any idea how I can solve this issue? 您是否知道如何解决这个问题?

Not sure what exactly you want to get to, but to do something after a known interval (in this case store to DB), use setInterval(60 * 1000) which comes in javascript by default, or use the Math Mod operation. 不确定要确切地达到什么目的,但是要在已知间隔(在这种情况下,存储到DB)之后执行一些操作,请默认使用javascript中附带的setInterval(60 * 1000)或使用Math Mod操作。 eg: 例如:

if (seconds_counter % 60 === 0) {
    //Post to DB
    //seconds_counter, would need to increment every second by 1
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM