Fresh NestJS wrapper for Typegoose that solves the main drawback of nestjs-typegoose
For support, email me [email protected] or write an issue straight in kindagoose repository!
To install kindagoose
, you need to execute one of these simple commands:
$ npm i kindagoose @typegoose/typegoose mongoose
$ yarn add kindagoose @typegoose/typegoose mongoose
Full documentation is available here!
@modelOptions({ schemaOptions: { collection: 'Users' } })
export class User extends TimeStamps {
@prop({ unique: true })
login: string;
@prop()
firstName: string;
@prop()
lastName: string;
@prop({ type: () => Date })
age: Date;
@prop()
password: string;
@prop({ type: () => [Task], localField: '_id', foreignField: 'owner_id' })
tasks: Ref<Task>[];
}
@Module({
imports: [
KindagooseModule.forFeature([
User,
]),
],
controllers: [],
providers: [UsersService],
})
export class UsersModule {}
import { InjectModel } from "kindagoose";
import { ReturnModelType } from "@typegoose/typegoose";
@Injectable()
export class UsersService {
constructor(
@InjectModel(User)
private readonly userModel: ReturnModelType<typeof User>,
) {}
async create(createUserDto: CreateUserDto) {
return this.userModel.create(createUserDto);
}
async get({ limit, offset }: PaginationDto) {
return this.userModel.find().skip(offset).limit(limit).exec();
}
async getById(id: string) {
return this.userModel.findById(id).exec();
}
}