Skip to content

module

mongodb

MongoDB through your own API route. Atlas retired its HTTP Data API (September 2025), and a database password must never reach the browser, so the browser sends Commands to a server route (generated by weft add mongodb), which checks them against a Policy and runs them with the official driver.

let db = Mongo::new("/api/mongo");
let req = db.find("products", json!({ "tags": "lamp" })).sort(json!({ "price": 1 })).limit(12).request();
let docs = mongodb::parse_documents(&weft::web::fetch(req).await?)?;

Structs

  • Builder

    A MongoDB command being built, sent with [Builder::request].

  • Command

    One database operation, as JSON (filters in MongoDB Extended JSON, so {"_id": {"$oid": "…"}} matches an ObjectId).

  • Mongo

    The browser side: builds commands for your API route.

  • Policy

    Which collections the browser may use, and how.

Enums

  • Access

    What a policy allows on a collection.

  • Action

    What a command does.

Functions

iso_from_millis

pub fn iso_from_millis(ms: i64) -> String

Milliseconds since the epoch → YYYY-MM-DDTHH:MM:SS.mmmZ.

parse_documents

pub fn parse_documents(res: &Response) -> Result<Value, Error>

The documents from a find/aggregate (or the one from findOne) as a list of records.

reply_documents

pub fn reply_documents(docs: Vec<Value>) -> Value

The reply body for each action (used by the server route).

reply_error

pub fn reply_error(message: &str) -> Value

The route's JSON reply for an error.

simplify

pub fn simplify(j: &Value) -> Value

Relaxed Extended JSON → plain JSON: {"$oid": x} → x, {"$date": …} → an ISO string, $numberLong/$numberInt/$numberDouble/ $numberDecimal → numbers.