MongoDB
Finds, inserts, updates or deletes documents in a MongoDB collection. Find hands them over as JSON for For Each or Read JSON, such as today's orders; Insert adds one document or a JSON list of them; Update changes the first document that matches the filter, or every one; Delete deletes them. Continues on Failed with the reason in Error when the server can't be reached or refuses it, such as a duplicate _id.
Settings
| Setting | Starts as | What it does |
|---|---|---|
| Operation | Find |
Find only reads; Insert, Update and Delete change the collection. |
Server ${} |
localhost |
The MongoDB server's name or IP address, such as localhost or 192.168.1.10. Not used when Connection string is filled in. |
Database * ${} |
empty | For example, shop. |
Collection * ${} |
empty | For example, orders. |
| Filter | empty | Which documents, as JSON, such as {"status": "@status"} or {"total": {"$gt": "@min:number"}}. {} matches every document; so does an empty Filter, except for Delete, which needs one. It runs as typed; MacroWin values go in Parameters and are named here as "@name". |
| Documents * | empty | One document, such as {"name": "@name", "total": "@total:number"}, or a list [{...}, {...}]. It runs as typed; MacroWin values go in Parameters and are named here as "@name". |
| Changes * | empty | Update operators, such as {"$set": {"status": "@status"}, "$inc": {"visits": 1}}; with Replace the whole document, the new document. It runs as typed; MacroWin values go in Parameters and are named here as "@name". |
Parameters ${} |
empty | One per line as name = value, such as customer = ${name}. The query names one as "@customer" (text), or "@age:number", "@paid:bool", "@since:date", "@id:id" (an ObjectId). The value goes in as a value of its own, so quotes or operators in it can't change the query. |
| Sort | empty | The order, such as {"date": -1} for the newest first. Empty: the server's own order. It runs as typed; MacroWin values go in Parameters and are named here as "@name". |
| Fields | empty | Which fields to return, such as {"name": 1, "total": 1}. Empty: all of them. It runs as typed; MacroWin values go in Parameters and are named here as "@name". |
| Limit | 100 |
At most this many documents. 0 returns every one, which can be a lot. |
| Every matching document | Off |
Off: only the first that matches. For Delete, on with the filter {} deletes every document in the collection. |
| Insert when nothing matches | Off |
On: a new document is made from the filter and the changes when none matches. |
| Replace the whole document | Off |
On: Changes is the new document, which takes the matching one's place (keeping its _id). |
Connection string ${} |
empty | Instead of the server fields: mongodb://... or mongodb+srv://... as MongoDB Atlas or Compass copies it. Stored as a password, since it usually holds one. |
| Port | 27017 |
Usually 27017. |
User name ${} |
empty | Leave it empty for a server without sign-in. Signs in against the admin database. |
Password ${} |
empty | The user's password. Stored as a password. |
| TLS | Off |
|
| Time limit (ms) | 10000 |
For reaching the server and the operation. 0 waits as long as it takes. |
Settings marked ${} take variables. * is required.
Where it continues
- Out when it's done.
- Failed when the server can't be reached, refuses the sign-in or the command, or doesn't answer in time; the reason is in Error.
Outputs
| Documents | One document per line, each as JSON, for For Each. |
|---|---|
| JSON list | All documents as one JSON list, for Read JSON (items[0].name). |
| First | The first document as JSON; empty when none was found. |
| Count | Find: how many were found. Insert: how many were inserted. |
| IDs | Each new document's _id, one per line (an ObjectId as its 24 hex digits). |
| ID | Insert: the first new document's _id. Update: the new document's _id when Insert when nothing matches made one; empty otherwise. |
| Matched | How many documents matched the filter. |
| Changed | How many were changed (a document that already had the values isn't), with one inserted counted. |
| Deleted | How many documents were deleted. |
| Error | Why it failed; empty when it worked. |
More in Databases: Redis, Run SQL
Build macros with MongoDB in MacroWin. Free to download, no account needed. Windows 10 and 11.
Download