Skip to main content
Access schema methods via client.schema. This module allows you to programmatically retrieve the definitions of your collections, which is useful for building dynamic forms or data table components.

getSchema

Fetch the schema definition for a specific collection.
getSchema(collection: string): Promise<CollectionSchema>
Returns (CollectionSchema)
FieldTypeDescription
namestringThe name of the collection.
modelSchemaField[]Array of field definitions.
SchemaField Object
FieldTypeDescription
keystringThe field name.
typestringThe Mongoose type (e.g. "String", "Number", "Ref", "Array").
requiredbooleanWhether the field is mandatory.
uniquebooleanWhether the field has a uniqueness constraint.
refstringIf type is "Ref", the target collection name.
itemsobjectElement type definition when type is "Array". Contains type and optional nested fields.
fieldsSchemaField[]Nested field definitions for embedded objects or sub-documents.
Example
const schema = await client.schema.getSchema('products');

console.log(schema.name); // 'products'
console.log(schema.model[0].key); // 'name'
console.log(schema.model[0].type); // 'String'