Hello everyone,
I am currently running a project in which I am uploading shipment data (just numbers) to a MongoDB with the help of Node Red. To do this, I have built certain input fields into the NodeRed dashboard. The shipment number can be entered there together with other shipment data. The data is then bundled in a JSON file using a JOIN node and transferred to MongoDB. Now the task: I want to access data that belongs to a specific shippment number. To do this, I have added a text input field in the Node Red dashboard where the shipment number to be searched for in the Mongo DB can be entered. The associated data should be displayed on the dashboard in a text output field. I already have set up a connection to mongo db but when i type in a shipment number, all data is displayed on the dashboard.
Can somebody help? I am a beginner in the field of node red
Thanks in advance!
Hi Colin, here is an excerpt of the data from my MongoDB. In the previous step, various data is bundled together and transferred to MongoDB.
Now I would like to add a field to the dashboard in Node Red in which I enter for example the parentID number: urn:epc:id:grai:2 and node red then calls up exactly this entry from the database, with all the associated payload as shown in Figure 1
Unfortunately, it currently looks like this for me: (All entries in the Mongo Db are simply returned)
Which mongodb node have you installed (I see several in flows.nodered.org)?
I don't know anything about mongodb, but presumably you have to build a query that you pass to the database. Do you know what query you need to use to get the records for a particular parentID?
Do you mean you don't know what mongodb query you need to run (in which case that isn't a node-red question, and I don't know how to do it), or that you know the query but don't know how to configure msg.payload to contain the query?
Forget for the moment that you are using node-red, and give us an example of the mongodb query that you want to perform to fetch, for example, the data for urn:epc:id:grai:2.
Hi, yes the question is how to restrict it correctly.
My Mongo-DB in node only allows the operation "Find". As a result, I simply get back all the contents of the MongoDB each time I query. But I only want to get back the entries that are together with a specific number that I enter in the dashboard.
I have now tried using a function after the mongodb in Node.
Here I was at least able to use msg.protection to limit the fields that I want to have displayed. Now I only get the restricted fields back, but again from all data records and not just those for a specific number.
As I said, please forget about how to do it in node-red for the moment. You need to do some research into the find command in mongodb to work out how to select the data you want.
To explain more clearly. If you were working using MySQL then you would have to use a query something like
SELECT * FROM some_table WHERE `parent_id` = "urn:epc:id:grai:2"
Once you have worked out what syntax you need in the find command then we can help you get that going in node-red.
Possibly you should look at using different client for mongodb in order to experiment with it, then once you understand mongodb better then implement it in node-red
I have now customised the function as follows.
"searchvalue" should be the value of the msg.payload that I enter in the dashboard.
I have set it so that initially only the parentIDs are displayed. Nevertheless, all parentIDs are displayed when I enter "urn:epc:id:grai:333" in the dashboard field.
you mean you still get all the db records without any filtering done ?
I tried those mongodb-aleph nodes on my test mongodb and having the query in msg.payload works for me.
Can you put a Debug node and show us the msg coming out of Function 7 ?
Can you double check if your Operation in the node config is set to "find" Could it be that your NR is set to German language and Find operation shows up as "Finden" .. could that interfere with the Node's logic ?
I have temporarily replaced the text input field with an inject node, which generates an msg.payload with a query value as an example. (later the msg.payload should, in the best case, be able to be entered variably in the dashboard)
This is followed by the function:
With the current settings, I no longer get any values back: