With TanStack Start
Use Mongster inside server functions and keep the client bundle clean
TanStack Start already separates server-only code well, which makes Mongster integration straightforward. Connect in a shared server module and call your models inside createServerFn() handlers.
import { } from "@tanstack/react-start";
import { , , } from "mongster";
const = .({
: .().(1),
: .().(false),
}).();
const = ("todos", );
let = false;
async function () {
if () return;
await .("mongodb://127.0.0.1:27017/start-app");
= true;
}
export const = ({ : "POST" })
.((: { : string }) => )
.(async ({ }) => {
await ();
const = await .({
: .,
});
return
? {
: ..(),
: .,
: .,
}
: null;
});This keeps Mongster on the server side only, while still giving your UI a typed server-function boundary.