MongoDB REST API without code: webhook, database operation, answer
A MongoDB REST API without code is a ready nana800 template: a webhook takes a request with the collection, filter and data, the MongoDB block runs the operation on your database, and the result goes back to the sender. No server is needed, only a connection string to your MongoDB or Atlas database. Each API request costs three basic block runs, and your balance is topped up to $3.50 for free every month.
Build it in the builder
Chain of blocks
- 1
Trigger
button starts the scheme by hand for a test. The database block takes the collection and filter from the request, so put test values into its fields before a button test, or test the scheme on the API page.
- 2
Trigger · Webhook (trigger)
webhook is the address of your API. It takes JSON with the fields collection, filter (always send it, at least {}) and data (the data to write).
- 3
Action · MongoDB operation
Mongodb Database external operation runs the operation on your database. The template uses FIND_ONE, which finds one record, takes the collection and filter from the request, and you add the connection string.
- 4
Action · Webhook response
webhook response answers the sender with code 200 and JSON with a success field and the operation result in the data field.
What it is good for
- Serve MongoDB data to a website or mobile app: a product, an order, a client profile
- Take leads and orders from a website and save them to a collection with CREATE_ONE
- Change an order status on a request from a CRM or a payment service with the $set operator
- Build an app prototype with no server of your own: each API address is a separate webhook with its own operation
- Give no-code services access to the database: any service that can send requests reads and writes records
How to set it up
- 1
Open the template
In the builder open Templates, find Simple REST API with MongoDB and press Use. A scheme with four connected blocks appears in the project you pick.
- 2
Paste the connection string
In the Mongodb Database external operation block replace the text in the connection string field with the address of your database, for example mongodb+srv://user:password@cluster0.xxxxx.mongodb.net/dbname. Encode special characters in the password, for example @ as %40. The database must be reachable from the internet: in Atlas allow access in Network Access.
- 3
Pick the operation and collection
The template uses FIND_ONE. For new records pick CREATE_ONE: the data field of the request goes into the data to write. For edits pick UPDATE_ONE, then data uses an operator, for example {"$set": {"status": "done"}}. It is safer to type the collection name into the block than to take it from the request.
- 4
Set up the webhook
In the webhook block set method to POST: the template has GET, but the data comes in the request body. In path enter a path such as /orders/find. For other operations add more webhooks with their own paths, each with its own MongoDB block and answer.
- 5
Fix the response body
In the webhook response block the result is inserted in quotes, but a found record is a JSON object, so the answer becomes invalid JSON. Move the body to the body json field, remove the quotes around the result insert and clear body raw. Then the sender gets the record as normal JSON.
- 6
Turn the scheme on and test it
Turn the scheme on, press the API button in the builder and on the Try it tab send JSON like {"collection": "orders", "filter": {"status": "new"}}. The request really runs on your database, and the answer contains the found record. An enabled scheme costs $0.0042 per hour.
Services in this template
- Webhook
Receive website leads and service events with a webhook and answer requests with no server and no code. Free balance every month, no card needed.
- MongoDB
Connect MongoDB or Atlas to nana800: find, create, update and delete documents from a scheme with no server of your own. Free balance every month, no card needed.
Frequently asked questions
Build your first scheme for free
Sign-up is free and needs no card. Every month the balance is topped up to $3.50 for free, enough for about 3,500 runs of basic blocks.
Build it in the builder