data
MongoDB Atlas Lua API for KosmoKrator Agents
Agent-facing Lua documentation and function reference for the MongoDB Atlas KosmoKrator integration.Lua Namespace
Agents call this integration through app.integrations.mongodb.*.
Use lua_read_doc("integrations.mongodb") inside KosmoKrator to discover the same reference at runtime.
Call Lua from the Headless CLI
Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic
MongoDB Atlas workflow without starting an interactive agent session.
kosmo integrations:lua --eval 'dump(app.integrations.mongodb.find_documents({database = "example_database", collection = "example_collection", filter = "example_filter", projection = "example_projection", sort = "example_sort", limit = 1, skip = 1}))' --json kosmo integrations:lua --eval 'print(docs.read("mongodb"))' --json
kosmo integrations:lua --eval 'print(docs.read("mongodb.find_documents"))' --json Workflow file
Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.
local mongodb = app.integrations.mongodb
local result = mongodb.find_documents({database = "example_database", collection = "example_collection", filter = "example_filter", projection = "example_projection", sort = "example_sort", limit = 1, skip = 1})
dump(result) kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json integrations:lua exposes app.integrations.mongodb, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.mongodb.default.* or app.integrations.mongodb.work.* when you configured named credential accounts.
MCP-only Lua
If the script only needs configured MCP servers and does not need MongoDB Atlas, use the narrower mcp:lua command.
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json Agent-Facing Lua Docs
This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.
MongoDB Atlas Data API Lua Reference
Namespace: mongodb
This integration targets the deprecated MongoDB Atlas Data API v1 compatibility surface. It covers the official document action endpoints: find, findOne, insertOne, insertMany, updateOne, updateMany, deleteOne, deleteMany, and aggregate.
The configured endpoint URL must end in /endpoint/data/v1. The package adds dataSource from integration credentials, defaulting to mongodb-atlas.
Tools
mongodb.find
Query documents in a collection.
local result = app.integrations.mongodb.find({
database = "app",
collection = "customers",
filter = { status = "active" },
projection = { email = 1, status = 1, _id = 0 },
sort = { createdAt = -1 },
limit = 25
})
Returns the Data API response, usually { documents = { ... } }.
mongodb.find_one
Return the first document matching a filter.
local result = app.integrations.mongodb.find_one({
database = "app",
collection = "customers",
filter = { email = "person@example.test" }
})
mongodb.insert_one
Insert one document.
local result = app.integrations.mongodb.insert_one({
database = "app",
collection = "customers",
document = { email = "person@example.test", status = "active" }
})
Returns the Data API inserted id response.
mongodb.insert_many
Insert multiple documents.
local result = app.integrations.mongodb.insert_many({
database = "app",
collection = "events",
documents = {
{ type = "signup", user = "user-1" },
{ type = "login", user = "user-1" }
}
})
mongodb.update_one
Update one matching document.
local result = app.integrations.mongodb.update_one({
database = "app",
collection = "customers",
filter = { email = "person@example.test" },
update = { ["$set"] = { status = "paused" } }
})
mongodb.update_many
Update every matching document. Use a precise filter for broad writes.
local result = app.integrations.mongodb.update_many({
database = "app",
collection = "customers",
filter = { status = "trial" },
update = { ["$set"] = { status = "active" } }
})
mongodb.delete_one
Delete one matching document.
local result = app.integrations.mongodb.delete_one({
database = "app",
collection = "customers",
filter = { email = "person@example.test" }
})
mongodb.delete_many
Delete every matching document. An empty filter can delete an entire collection, so agents should require explicit user intent before using it.
local result = app.integrations.mongodb.delete_many({
database = "app",
collection = "sessions",
filter = { expired = true }
})
mongodb.aggregate
Run a MongoDB aggregation pipeline.
local result = app.integrations.mongodb.aggregate({
database = "app",
collection = "events",
pipeline = {
{ ["$match"] = { type = "signup" } },
{ ["$group"] = { _id = "$campaign", count = { ["$sum"] = 1 } } }
}
})
Returns the Data API aggregation response, usually { documents = { ... } }.
Notes
MongoDB marks the Atlas Data API v1 as deprecated. New integrations that need Atlas project administration should use MongoDB’s Atlas Administration API instead; it has different authentication and is not covered by this package.
Raw agent markdown
# MongoDB Atlas Data API Lua Reference
Namespace: `mongodb`
This integration targets the deprecated MongoDB Atlas Data API v1 compatibility surface. It covers the official document action endpoints: find, findOne, insertOne, insertMany, updateOne, updateMany, deleteOne, deleteMany, and aggregate.
The configured endpoint URL must end in `/endpoint/data/v1`. The package adds `dataSource` from integration credentials, defaulting to `mongodb-atlas`.
## Tools
### `mongodb.find`
Query documents in a collection.
```lua
local result = app.integrations.mongodb.find({
database = "app",
collection = "customers",
filter = { status = "active" },
projection = { email = 1, status = 1, _id = 0 },
sort = { createdAt = -1 },
limit = 25
})
```
Returns the Data API response, usually `{ documents = { ... } }`.
### `mongodb.find_one`
Return the first document matching a filter.
```lua
local result = app.integrations.mongodb.find_one({
database = "app",
collection = "customers",
filter = { email = "person@example.test" }
})
```
### `mongodb.insert_one`
Insert one document.
```lua
local result = app.integrations.mongodb.insert_one({
database = "app",
collection = "customers",
document = { email = "person@example.test", status = "active" }
})
```
Returns the Data API inserted id response.
### `mongodb.insert_many`
Insert multiple documents.
```lua
local result = app.integrations.mongodb.insert_many({
database = "app",
collection = "events",
documents = {
{ type = "signup", user = "user-1" },
{ type = "login", user = "user-1" }
}
})
```
### `mongodb.update_one`
Update one matching document.
```lua
local result = app.integrations.mongodb.update_one({
database = "app",
collection = "customers",
filter = { email = "person@example.test" },
update = { ["$set"] = { status = "paused" } }
})
```
### `mongodb.update_many`
Update every matching document. Use a precise filter for broad writes.
```lua
local result = app.integrations.mongodb.update_many({
database = "app",
collection = "customers",
filter = { status = "trial" },
update = { ["$set"] = { status = "active" } }
})
```
### `mongodb.delete_one`
Delete one matching document.
```lua
local result = app.integrations.mongodb.delete_one({
database = "app",
collection = "customers",
filter = { email = "person@example.test" }
})
```
### `mongodb.delete_many`
Delete every matching document. An empty filter can delete an entire collection, so agents should require explicit user intent before using it.
```lua
local result = app.integrations.mongodb.delete_many({
database = "app",
collection = "sessions",
filter = { expired = true }
})
```
### `mongodb.aggregate`
Run a MongoDB aggregation pipeline.
```lua
local result = app.integrations.mongodb.aggregate({
database = "app",
collection = "events",
pipeline = {
{ ["$match"] = { type = "signup" } },
{ ["$group"] = { _id = "$campaign", count = { ["$sum"] = 1 } } }
}
})
```
Returns the Data API aggregation response, usually `{ documents = { ... } }`.
## Notes
MongoDB marks the Atlas Data API v1 as deprecated. New integrations that need Atlas project administration should use MongoDB's Atlas Administration API instead; it has different authentication and is not covered by this package. local result = app.integrations.mongodb.find_documents({database = "example_database", collection = "example_collection", filter = "example_filter", projection = "example_projection", sort = "example_sort", limit = 1, skip = 1})
print(result) Functions
find_documents Read
Query documents from a MongoDB Atlas collection. Supports filtering, projection, sorting, pagination (limit/skip). Returns an array of matching documents.
- Lua path
app.integrations.mongodb.find_documents- Full name
mongodb.mongodb_find
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
filter | object | no | MongoDB query filter (e.g., {"status": "active"}). Defaults to {} (all documents). |
projection | object | no | Fields to include/exclude (e.g., {"name": 1, "_id": 0}). |
sort | object | no | Sort specification (e.g., {"createdAt": -1}). |
limit | integer | no | Maximum number of documents to return. |
skip | integer | no | Number of documents to skip (for pagination). |
find_one_document Read
Find a single document in a MongoDB Atlas collection. Returns the first matching document or null if no match is found.
- Lua path
app.integrations.mongodb.find_one_document- Full name
mongodb.mongodb_find_one
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
filter | object | no | MongoDB query filter (e.g., {"_id": {"$oid": "..."}}). Defaults to {} (first document). |
projection | object | no | Fields to include/exclude (e.g., {"name": 1, "_id": 0}). |
insert_document Write
Insert a single document into a MongoDB Atlas collection. Returns the inserted document ID.
- Lua path
app.integrations.mongodb.insert_document- Full name
mongodb.mongodb_insert_one
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
document | object | yes | The document to insert (e.g., {"name": "Alice", "age": 30}). Do not include _id unless you want a custom value. |
insert_many_documents Write
Insert multiple documents into a MongoDB Atlas collection in a single operation. Returns the inserted document IDs.
- Lua path
app.integrations.mongodb.insert_many_documents- Full name
mongodb.mongodb_insert_many
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
documents | array | yes | Array of documents to insert (e.g., [{"name": "Alice"}, {"name": "Bob"}]). |
update_one_document Write
Update a single document in a MongoDB Atlas collection. Uses a filter to match the document and an update operations object (e.g., {"$set": {"field": "value"}}).
- Lua path
app.integrations.mongodb.update_one_document- Full name
mongodb.mongodb_update_one
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
filter | object | yes | MongoDB query filter to match the document (e.g., {"_id": {"$oid": "..."}}). |
update | object | yes | Update operations (e.g., {"$set": {"status": "active"}}). Use MongoDB update operators like $set, $inc, $push, etc. |
update_many_documents Write
Update multiple documents in a MongoDB Atlas collection. Uses a filter to match documents and an update operations object such as {"$set": {"status": "active"}}.
- Lua path
app.integrations.mongodb.update_many_documents- Full name
mongodb.mongodb_update_many
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
filter | object | yes | MongoDB query filter to match documents. Use a specific filter for destructive or broad updates. |
update | object | yes | Update operations such as {"$set": {"status": "active"}}. |
delete_one_document Write
Delete a single document from a MongoDB Atlas collection. Uses a filter to match the document to delete.
- Lua path
app.integrations.mongodb.delete_one_document- Full name
mongodb.mongodb_delete_one
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
filter | object | yes | MongoDB query filter to match the document to delete (e.g., {"_id": {"$oid": "..."}}). |
delete_many_documents Write
Delete multiple documents from a MongoDB Atlas collection. Use a precise filter; an empty filter can delete every document in the collection.
- Lua path
app.integrations.mongodb.delete_many_documents- Full name
mongodb.mongodb_delete_many
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
filter | object | yes | MongoDB query filter to match documents to delete. |
aggregate Read
Run an aggregation pipeline on a MongoDB Atlas collection. Supports all pipeline stages ($match, $group, $sort, $project, $limit, $lookup, etc.).
- Lua path
app.integrations.mongodb.aggregate- Full name
mongodb.mongodb_aggregate
| Parameter | Type | Required | Description |
|---|---|---|---|
database | string | yes | The database name. |
collection | string | yes | The collection name. |
pipeline | array | yes | Array of pipeline stages (e.g., [{"$match": {"status": "active"}}, {"$group": {"_id": "$category", "count": {"$sum": 1}}}]). |