createSchema
@abimongo/core / createSchema
Function: createSchema()
createSchema<
T>(schema):AbimongoSchema<T>
Defined in: core/src/utils/builders/schema.ts:23
Creates a new AbimongoSchema instance with the provided schema definition.
Type Parameters
T
T extends Document
The type of the document.
Parameters
schema
The schema definition for the document.
SchemaDefinition<T> | Record<keyof T, any>
Returns
The created AbimongoSchema instance.
Example
const userSchema = createSchema({
name: { type: String, required: true },
age: { type: Number, required: true },
email: { type: String, required: true },
});
const userModel = new AbimongoModel(userSchema, 'users', db);
const user = await userModel.create({ name: 'John Doe', age: 30, email: 'example.com' });
console.log(user); // { _id: '...', name: 'John Doe', age: 30, email: 'example.com' }