Skip to content

useMongocampViews ​

Runs the declared views of a collection (server 2.10, POST /mongodb/collections/{name}/views/{view}). The views of a collection are in its declaration (useMongocampDeclaration: views, each { name, hasParams, description? }).

ts
const { runView } = useMongocampViews()
const { rows, total, pages, page } = await runView('orders', 'byStatus', { status: 'paid' }, { page: 1, rowsPerPage: 20 })
FunctionReturns
runView(collection, view, params = {}, { page, rowsPerPage, signal })ViewResult: rows (plain values via unwrapExtendedJson; integers beyond 2^53 as exact digit strings — read from the response text), total (x-pagination-count-rows), pages, page

The parameters go as { params } (Extended JSON); the server validates them against the view's schema and answers a refusal with 400, code 4010, and issues — useMongocampError().describeServerError gives kind invalid with the issues. An unknown view (or a collection without it) is a 404. 30 s timeout; signal aborts. Parse an editor's text with parseViewParams from utils/viewParams.ts (one object; empty = {}).

MongocampCollectionView is the ready-made UI.

Released under the MIT License.