# Inject serial data in JSON file then insert them in MongoDB

**URL:** <https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512>\
**Category:** General\
**Created:** [12 May 2020 08:51 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512 "2020-05-12T08:51:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elvyn](https://avatars.discourse-cdn.com/v4/letter/e/ecb155/32.png) [@Elvyn](https://discourse.nodered.org/u/Elvyn)\
**Post date:** [12 May 2020 08:51 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/1 "2020-05-12T08:51:30Z")

</div>

Hello everyone,

I would like to inject this data in a JSON file, but I dont know how to do that. After that Ive to insert them in MongoDB.  
Im french student, this one part of my final project of my studies. I Can traduce you some words if you dont understand.

 ![IMG_20200512_104645](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/205bcec60f928c4ef26a6ef78e5c77cde7815868.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 May 2020 10:16 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/2 "2020-05-12T10:16:40Z")

</div>

I don't know what you mean by a JSON file, but to write data to a file look at the File nodes which are part of the standard node-red install.

---

<div class="post-metadata">

**Author:** ![Elvyn](https://avatars.discourse-cdn.com/v4/letter/e/ecb155/32.png) [@Elvyn](https://discourse.nodered.org/u/Elvyn)\
**Post date:** [12 May 2020 11:05 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/3 "2020-05-12T11:05:45Z")

</div>

I was thinking that if I put output data in a JSON file, it will be easier to store them in my DB..  
But if they is a another way to do that, I want to know !  
At the moment, Ive no idea how to send these data to my DB execpt with JSON

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 May 2020 12:25 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/4 "2020-05-12T12:25:44Z")

</div>

I still don't know what you mean by a JSON file. Exactly what do you want to put in the file, give us an example of what the data should look like.  
I don't know about Mongodb.

**[Edit]** I have just corrected my question, I meant what do you want to put in the file, as the question now says.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 May 2020 12:50 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/5 "2020-05-12T12:50:46Z")

</div>

There are many examples of mongoDB on this forum use the search.

When you find something & try it out - but get stuck, come back & ask specific questions.

The people on this forum are very helpful - but they wont do it all for you i'm afraid.

As for writing JSON to file (not sure why you want to - just put data straight into Mongo) but anyway - look at the node-red-contrib-flogger node - it handles writing Js objects as JSON to file nicely.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 May 2020 12:53 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/6 "2020-05-12T12:53:29Z")

</div>

Though note that the data you showed in the debug at the start is not JSON, they are just strings.

---

<div class="post-metadata">

**Author:** ![Elvyn](https://avatars.discourse-cdn.com/v4/letter/e/ecb155/32.png) [@Elvyn](https://discourse.nodered.org/u/Elvyn)\
**Post date:** [13 May 2020 07:25 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/7 "2020-05-13T07:25:43Z")

</div>

Ok, I dont looking for the all code ! Il looking for solution to extract the data on the picture, its different.. so, how with which procede Can I extract these string ?  
I just want to have these data in a file to store them in a DB, but Im Node Red beginner..  
Do you have some extension files to advice me ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 May 2020 07:28 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/8 "2020-05-13T07:28:17Z")

</div>

> [@Elvyn](#):
>
> Can I extract these string

What do you mean, extract the strings? They are there for you to do what you want with, you don't need to extract them. Have a read of the node-red docs on Working with Messages, it may be helpful.  
[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![Elvyn](https://avatars.discourse-cdn.com/v4/letter/e/ecb155/32.png) [@Elvyn](https://discourse.nodered.org/u/Elvyn)\
**Post date:** [13 May 2020 07:31 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/9 "2020-05-13T07:31:30Z")

</div>

Thanks, I will take a look

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 July 2020 07:40 UTC](https://discourse.nodered.org/t/inject-serial-data-in-json-file-then-insert-them-in-mongodb/26512/10 "2020-07-12T07:40:48Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
