Cancel
Showing results for 
Search instead for 
Did you mean: 

Stream data to mongoDB

Creator
Creator

Hi all,

 

I would like to implement a sort of data stream from the Mindsphere timeseries service to my MongoDB database without interaction on the front end of my application. (I am working with a Node js backend, React scripts frontend and a mongoDB database).

 

Example:

I have data arriving into the mindsphere timeseries database at regular intervals, I would like my backend to make a GET request to the MDSP and then without any user interaction save this to my MongoDB database.

 

I can perform each request individually, but both require frontend interaction. Either with a componentDidMount() and intervalIsSet combination or a simple button with an onClick() function linked with it.

 

Has anybody got any suggestions on where to start or any experience with this type of backend functionality?

 

All suggestions welcomed.

Thanks

1 REPLY 1

Re: Stream data to mongoDB

Siemens Valued Contributor Siemens Valued Contributor
Siemens Valued Contributor

You could write backend application that would make Mindsphere API calls at regular interval.

If you are developing backend app in  JAVA spring boot for example then you could use "schedule" task https://spring.io/guides/gs/scheduling-tasks/

In Node.js back end you could use https://www.npmjs.com/package/node-schedule

 

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
│    │    │    │    └───── month (1 - 12)
│    │    │    └────────── day of month (1 - 31)
│    │    └─────────────── hour (0 - 23)
│    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, OPTIONAL)

I guess, since your manual UI action is working fine from UI, you are already aware of necesary timeseries API calls to get latest timeseries data and API call to save to mongo db.

Please  also ensure that the interval at which you make Mindsphere Timeseries API call is appropriate and does not generate huge and unncessary traffic.

 

Additionally,  Mindsphere  - Visual Flow Creator has node "subscribe timeseries"  node that allows to "subscribe" to timeseries changes for the given asset/aspect/variable combination. Thus, you could consider using VFC flow to save timeseries in your mongodb

https://documentation.mindsphere.io/resources/pdf/visual-flow-creator-en.pdf

Subscribe timeseries node
The "subscribe timeseries“ node subscribes time series data from MindSphere.
You use this node to:
● Get notifications of new incoming time series data in order to perform tasks.
● Get updates on the new timeseries data which is posted in IOT.
Requirements:
● Asset, aspect and a variable must be defined in MindSphere.
Once the subscription is created, it can take up to 15 minutes for the service to start working.