How-To Guides
Flows Guides
Work with MongoDB Databases
10min
you can use flows to establish a connection with the mongodb database and complete operations on it step 1 install mongodb in litmus edge to install mongodb in litmus edge navigate to applications > marketplace click marketplace list and select default marketplace catalog search and click the mongodb tile installation script version from the drop down list, select latest name enter a name for the application leave the other fields with their default values click launch navigate to applications > catalog apps to ensure the application is running successfully troubleshooting if you have any issues installing mongodb, do the following check system > info to make sure that you have enough space on your edge device make sure that you do not have any network connectivity issues navigate to applications > catalog apps and click the mongodb application tile to view the logs review any errors step 2 create flow to start creating the flow in litmus edge, navigate to the flows manager and create a new flow see create a flow docid\ veyyte7xdcangglzbqya0 to learn more you can create flows with mongodb nodes to do the following read the inserted values update the values remove the values from the database there are three mongodb nodes available on the flow canvas mongodb in allows simple queries such as find and count mongodb out allows operations such as insert , update , and remove mongodb3 in allows more complex operations such as mapreduce configure mongodb node you will first need to configure a database connection for the mongodb node you can set up the configuration once and use it for all mongodb nodes in the same flows manager to configure the mongodb node drag and double click a mongodb3 in node on the canvas the edit mongodb3 in node dialog box appears server click the edit icon configure the properties for the node mongodb does not require a username or password by default, so you can leave this blank unless you set them previously uri enter the ip address for your mongodb server it is mongodb //localhost <27017> mongodb //localhost <27017> if your mongodb instance is running on the same device as litmus edge click add or update click done and then click deploy insert values to insert new records into a mongodb database from the flow canvas, drag and connect an inject node, a function node, and a mongodb out node double click the function node the edit function node dialog box appears on message enter the following msg payload = {"column1" "value1", "column2" 15}; // change to be the keys and values appropriate for your database return msg; click done double click the mongodb out node the edit mongodb out node dialog box appers operation select insert only store msg payload object select the checkbox collection enter devicehub server configure the server setting if needed click done click deploy click the inject node button to insert records into the database each click inserts a new record with a new id ( id) read all records to retrieve all records from a mongodb collection from the flow canvas, drag and connect an inject node, a mongodb in node, and a debug node double click the mongodb in node the edit mongodb in node dialog box appears collection enter devicehub operation select find server configure the server setting if needed click done click deploy and expand the message window beneath the flow click the debug icon to view the output all the records are seen in the table read single record to retrieve a single record from a mongodb collection from the flow canvas, drag and connect an inject node, a function node, a mongodb3 in node, and a debug node from the flow canvas, drag and connect an inject node, a function node, a mongodb3 in node, and a debug node double click the mongodb3 in node the edit mongodb3 in node dialog box appears service select external service server select the server you created while configuring the mongodb node above operation select findone click done double click the function node the edit function node dialog box appears on message enter the following msg payload = {"column2" 16} // this line reads all records where column2 is equal to 16 return msg; click done click deploy and expand the message window beneath the flow click the inject node button to read the record that matches the specified key value pair view the record by clicking the debug icon update values to update values in a mongodb database in the flow canvas, drag and connect an inject node, a function node, and a mongodb out node double click the mongodb out node the edit mongodb out node dialog box appears collection enter devicehub operation select update update all matching documents select the check box click done double click the function node the edit function node dialog box appears on message enter the following msg query = {"column2" 15}; // this line makes the query only update records where column2 is equal to 15 msg payload = {"$set" { "column2" 20 }}; // this line uses the set operator to ensure that the update sets column2 to 20 for all matching records return msg; click done click deploy and expand the message window beneath the flow click the inject node to perform the update operation the records with column2 value as 15 are updated with 20 delete values to delete records from a mongodb database in the flow canvas, drag and connect an inject node, a function node, and a mongodb out node double click the mongodb out node the edit mongodb out node dialog box appears collection enter devicehub operation select remove click done double click the function node the edit function node dialog box appears on message enter the following msg payload = {"column2" 20}; // makes the remove operation delete all records where column2 equals 20 return msg; click done click deploy and expand the message window beneath the flow click the inject node to perform the remove operation the record with columns equal to 20 are deleted