# Retrieving certain data from a MongoDB

**URL:** <https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741>\
**Category:** Dashboard\
**Tags:** database\
**Created:** [15 December 2023 11:18 UTC](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741 "2023-12-15T11:18:32Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [16 December 2023 23:20 UTC](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741/21 "2023-12-16T23:20:44Z")

</div>

> [@Schlitz](#):
>
> I save the values differently than I want to retrieve them now

ok .. so this explains why you dont get a result now .. i was going to recommend to review the way you save the data in mongo because from your previous screenshot it seems that you were saving some unnecessary fields in each document (for example the data were nested under `payload`, saving topic, socketid, \_msgid )

> [@Schlitz](#):
>
> My input is done through 8 input fields on the Node Red dashboard, which are then bundeled together before I save them in MongoDB through a join node.

that can work but you could also use a Form ui\_form node that gathers all the data and sends them with a Submit button.

> [@Schlitz](#):
>
> Do I need to address the data differently to retrieve it?

Probably. It depends on how your data in mongodb looks like now after the changes you made  
Can you show us a screenshot of a couple of records ? (documents in mongodb)

---

<div class="post-metadata">

**Author:** ![Schlitz](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@Schlitz](https://discourse.nodered.org/u/Schlitz)\
**Post date:** [17 December 2023 00:12 UTC](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741/22 "2023-12-17T00:12:25Z")

</div>

Okay, I have now inserted a ui\_form node as you suggested (I have removed the individual text nodes and the join node)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/247b99147ded8d1c0b6ef4be6831799b451c6673.png)

However, I think the data is still stored in MongoDB in the same way: (The last one is made with the new ui\_form node - just typing "5" in every field

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e587c879c17ea688b6fe21ddf7bf8321d4a46752.png)

Here is my current data acquisition flow. Starting with the now new Ui\_Form Node, followd by a function "6" (In "function 6" I add a static addition to some values to bring them to a certain standard format): , after that uploading it with a mongoDB out node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/f/bfb3280f57328793c2103ac4e22ed894a1c14183.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [17 December 2023 00:20 UTC](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741/23 "2023-12-17T00:20:17Z")

</div>

> [@Schlitz](#):
>
> However, I think the data is still stored in MongoDB in the same way

In the mongodb out node .. that saves the new document ..  
do you have the option to save only the payload checked ?  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/ba860c30635f0b3b3c747d7fb0a53987746acd5c.png)

---

<div class="post-metadata">

**Author:** ![Schlitz](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@Schlitz](https://discourse.nodered.org/u/Schlitz)\
**Post date:** [17 December 2023 00:36 UTC](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741/24 "2023-12-17T00:36:44Z")

</div>

Thanks for the comment, I had forgotten about that.

Thats my complete flow now:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/195d91f384e4544c4079eb4d1b95648e7f98c8f5.png)

I have emptied my MongoDB and imported two new documents.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/a/9ac0256d7a1ff1326f7983d1299f427f550b003c.png)

However, the query still simply outputs all values (in this case now just the 2):  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3fd2ff06eb9759d6afd23d03522719d408dbb59b.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [17 December 2023 00:50 UTC](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741/25 "2023-12-17T00:50:18Z")

</div>

Much cleaner now with the db 👍

Whats in your Function 7 now ?  
it can be :

```auto
msg.payload = { "parentID": msg.payload }
// msg.projection = { "parentID" : 1 }
return msg;

```

---

<div class="post-metadata">

**Author:** ![Schlitz](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@Schlitz](https://discourse.nodered.org/u/Schlitz)\
**Post date:** [17 December 2023 01:26 UTC](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741/27 "2023-12-17T01:26:31Z")

</div>

Nice!  
Now it works with your code! Thanks!

(I will now make a few more adjustments.. i hope i can manage the rest on my own)

---

<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:** [15 February 2024 01:26 UTC](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741/28 "2024-02-15T01:26:54Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/retrieving-certain-data-from-a-mongodb/83741.md?page=1)
