Defining MongoDB Collections
Collections represent MongoDB collections. Define them by extending the Collection
class and using the @property
decorator for fields.
Example: User Collection
import { Collection, property } from 'hysteria-orm';
export class User extends Collection {
@property()
declare name: string;
@property()
declare email: string;
@property()
declare profile: {
age: number;
city: string;
};
}
Notes
- The
id
property is handled automatically and maps to MongoDB_id
. - You can use nested objects and arrays.
- MongoDB collections are schemaless, but decorators help with type safety.
Next: Collection Methods