You can fetch a specific version of a document in two different ways:
// By using the version method of the document:constdocument=awaitctx.document("document_path");constdocumentVersion=awaitdocument.data.getVersion("X.Y.Z");// By specifying the version directly the document path:constdocumentInVersionXYZ=awaitctx.document("document_path?v=X.Y.Z");
Create a Document
Steps to create a new document within a domain:
constdata=YOUR_AWESOME_JSON_DATA; // JSON data for the documentconsttemplates= ["template_path"]; // Optional array of template pathsconst metadata = { name: "Document Name", description: "Document Description", readme: "ctx:domain/files/my_markdown" }; // Optional metadata
constnewDocument=awaitctx.createDocument("document_path", data, templates, metadata);
You can add metadata to a document using the addMetadata method. The metadata object should contain the following (optional) fields: name, description, and readme as shown below: