This is the richest of the connected providers, and the one the agent tools were shaped around: a database it has never seen can be mapped, queried and written to without a schema being declared anywhere.
Connecting
const db = await api.storage.connect({
label: "Production",
type: "database",
provider: "mongodb",
endpoint: { credentials: { uri: "mongodb+srv://user:password@cluster.example.net/shop" } },
});db = api.storage.connect(
label="Production",
type="database",
provider="mongodb",
endpoint={"credentials": {"uri": "mongodb+srv://user:password@cluster.example.net/shop"}},
)credentials.uristringrequiredThe connection string. It carries the password, so it belongs in credentials, which is encrypted at rest.
…/shop is what picks the database. A URI with no path lands on a default one, which reads as empty — that is the usual explanation for « my collections are missing ».
What run() accepts
| Action | Reads or writes | Needs collection |
|---|---|---|
| overview | read | no |
| collections | read | no |
| schema | read | yes |
| find | read | yes |
| count | read | yes |
| aggregate | read | yes |
| search | read | no |
| insert | write | yes |
| update | write | yes |
| delete | write | yes |
| save | write | yes |
| createCollection | write | yes |
| dropCollection | write | yes |
Anything else raises Action MongoDB inconnue. tables, execute, list, object and upload belong to other providers.
_id may be a string
An identifier written as a 24-character string is turned into an ObjectId wherever one is expected: direct equality, $in, $nin and $ne. That is what lets an identifier travel through JSON — out of a find, into a form, back into an update — without a cast of yours in between.
const [order] = await db.run({ action: "find", collection: "orders", options: { limit: 1 } });
// order._id arrived as a string; it goes back as one
await db.run({
action: "update",
collection: "orders",
filter: { _id: order._id },
update: { $set: { status: "shipped" } },
});order = db.run(action="find", collection="orders", options={"limit": 1})[0]
# order["_id"] arrived as a string; it goes back as one
db.run(
action="update",
collection="orders",
filter={"_id": order["_id"]},
update={"$set": {"status": "shipped"}},
)Five operators are refused
$where, $function and $accumulator run JavaScript inside the database; $out and $merge write somewhere other than where you are looking. All five are refused on find, count, update, delete and aggregate, by inspecting the filter or the pipeline you sent.
await db.run({ action: "find", collection: "users", filter: { $where: "this.age > 30" } });
// Error: find : l'operateur $where n'est pas autorise.db.run(action="find", collection="users", filter={"$where": "this.age > 30"})
# IaGenifyError: find : l'operateur $where n'est pas autorise.Bounds that are imposed
| Thing | Bound |
|---|---|
aggregate result | 500 documents |
aggregate and count duration | 30 seconds |
insert batch | 1 to 500 documents |
overview | 30 collections, 25 fields, 1 sample each |
schema | 20 recent documents, 150 fields |
An empty filter is refused on a write
update and delete with no filter would touch every document, so they stop unless you add all: true. Reads have no such guard — an empty filter on find is an ordinary query.
The connection is kept
One client per URI is held and reused across calls, so the second run() does not reconnect. A URI that changes — a rotated password, a new host — is a new connection: it does not inherit the old one.
System collections are filtered out
collections and overview leave out anything in the system. namespace. What you see is what you put there.