MongoDB
MongoDB is a popular NoSQL document-oriented database that is widely used for web applications and other data-driven software. MongoDB is designed to be flexible, scalable, and fast, and is particularly well-suited for handling large amounts of unstructured or semi-structured data.
In Illa, you can connect to a MongoDB database using the MongoDB Query Resource. This resource allows you to execute MongoDB queries directly from Illa, without having to write any code. You can use the query editor to write queries in MongoDB's native query language, which is based on JavaScript and uses a JSON-like syntax for working with documents.
Create MongoDB
There are two ways to create a resource in Illa after signing into your Illa account.
- Create in Resources
Sign into your Illa account, select **Resources**
on the top of the page, and click **Create New**
button.
Select MongoDB
from the database list.
Connect to the database with the required parameters described in Connection Settings
below.
Click **Test Connection**
to see if we can successfully connect to the database. If yes, click Save Resources
, else, double check the hostname, port, username, and password is correct.
After creating a resource, the ready MongoDB will display as shown.
- Create in Builder
Sign into your Illa account, create a project in Illa Builder in the **App**
page, and navigate to the Action List
at the bottom of the page. Click **new**
, then select MongoDB
from the database list. Then, connect to the database with required parameters described in Connection Settings
below.
Click **Test Connection**
to see if we can successfully connect to the database. If yes, click Save Resources
, else, double check the hostname, port, username, and password is correct.
Connection Settings
Here we need to provide information for connecting to MongoDB database.
Properties | Required | Description |
---|---|---|
Name | required | The name for resource when creating actions in the ILLA. |
Config Type | optional | a type of collection used to store configuration data for sharded clusters. |
Hostname | required | The URL or IP address for your database |
Connection format | required | the syntax used to specify the connection string for connecting to a MongoDB database or cluster. |
Port | required | The server host's port number that you should use to connect. If you don't specify a port, default port is '3306'. |
Database | required | The name of the database |
Username | required | the username you wish to use when logging in to the MongoDB server. |
Password | required | Use this password for authentication. |
SSL options | optional | decides how high a secure SSL TCP/IP connection is prioritized while negotiating with the server. |
Create Actions
We have created a MongoDB resource, we can add the action by selecting MongoDB from action list and choosing the Create action
button.
Now we have added the MongoDB server as an action to our building page.
Configure MongoDB
Overview
Method Name | Description |
---|---|
Action Type | aggregate, bulkwrite, count, deleteMany. deleteOne, distinct, find, findOne |
Collection | group of related documents that are stored together in a database |
Transformer | transforming data into the style you like using JavaScript |
Aggregate
process multiple documents and return computed results.
Input
Properties | Required | Description |
---|---|---|
Aggregation | optional | defines the operations to be performed on the data |
For example, to get all the results whose size is medium=>group the results by type=>Calculate the sum of prices in each type for Aggregation
:
[
{
"$match": { "size": "medium" }
},
{
"$group": { "_id": "$type", "totalQuantity": { "$sum": "$price" } }
}
]
Output
An array of the computed results.
Use {{mongodb1.data[0].result}}
to get all.
Bulkwrite
perform multiple write operations (insert, update, and delete) in a single request to the server
Input
Properties | Required | Description |
---|---|---|
Operations | optional | an object that specifies the type of operation to perform and the data to be written |
An example for Operations
:
[
{ "insertOne": { "document": { "_id": 3, "type": "beef", "size": "medium", "price": 6 } } },
{ "insertOne": { "document": { "_id": 4, "type": "sausage", "size": "large", "price": 10 } } },
{ "updateOne": {
"filter": { "type": "cheese" },
"update": { "$set": { "price": 8 } }
}
}
]
Output
The updated message is showing below.
Since this method make changes but does not return anything. There is no output data to access.
Count
count the number of documents that match a given query in a collection
Input
Properties | Required | Description |
---|---|---|
Query | optional | specifies the selection criteria for the count operation |
For example, to count the number of item with type “beef”, we may put below code into Query
:
{"type":"beef"}
Output
The number of matching documents.
Use {{mongodb1.data}}
to get it.
deleteMany
delete multiple documents that match a given filter in a collection.
Input
Properties | Required | Description |
---|---|---|
Filter | optional | specifies the selection criteria for the delete operation, If not specified, all documents in this collection will be deleted. |
For example, to delete apples from items. We may put code below to Filter
.
{"type":"apple"}
Output
The number of matching documents.
Use {{mongodb1.data[0].result.DeletedCount}}
to get it. If no files are matched, the returned value will be 0.
deleteOne
delete one document that match a given filter in a collection.
Input
Properties | Required | Description |
---|---|---|
Filter | optional | specifies the selection criteria for the delete operation |
For example, to delete an apple from items. We may put code below to Filter
.
{"type":"apple"}
Output
Delete result.
Use {{mongodb1.data[0].result.DeletedCount}}
to get it. If no files are matched, the returned value will be 0 (Since we deleted all the apples in deleteMany
, there is no apple left, thus return 0).
distinct
retrieve an array of unique values for a specified field in a collection
Input
Properties | Required | Description |
---|---|---|
Query | optional | specifies the selection criteria for the distinct operation |
Field | required | specifies the field to retrieve the distinct values from. |
For example, we may have {"type":"orange"}
for Query
and _id
for Field
.
Output
an array of distinct values
Use {{mongodb1.data[0].result.map(item =>({"result":item}))}}
to get the array.
find
retrieve documents from a collection that match a specified set of criteria
Input
Properties | Required | Description |
---|---|---|
Query | optional | specifies the selection criteria for the find operation |
Projection | optional | specifies which fields to include or exclude in the query results |
Sort By | optional | specify the sorting order of the returned documents |
Limit | optional | limit the number of documents that are returned, default no limit. A limit of 0 is equivalent to no limit. |
Skip | optional | specify the number of documents to skip, default to 0. |
For example, to find the id, price, and type of all oranges sorted by their id.
For Query
, {"type": "orange"}
For Projection
, {"_id": 1, "type": 1, "price": 1}
For Sort By
, {"_id":1}
Note: replace “1” with “true” still do it!
Output
An array of objects of documents
Use {{mongodb1.data[0].result}}
to get the array.
findOne
retrieve the first document from a collection that match a specified set of criteria
Input
Properties | Required | Description |
---|---|---|
Query | optional | specifies the selection criteria for the find operation |
Projection | optional | specifies which fields to include or exclude in the query results |
Skip | optional | specify the number of documents to skip, default to 0. |
For example, to find the id, price, and type of all oranges sorted by their id.
For Query
, {"type": "orange"}
For Projection
, {"_id": 1, "type": 1, "price": 1}
Note: replace “1” with “true” still do it!
Output
An array of objects of documents
Use {{[mongodb1.data[0].result]}}
to get the array.