【发布时间】:2021-05-13 02:55:36
【问题描述】:
我正在使用 Nestjs 和 Mongodb 创建 API。 tasks.service.ts,试图创建一个 getAll 端点并得到打字稿错误:
Type 'Task' does not satisfy the constraint 'Document'. Type 'Task' is missing the following properties from type 'Document': increment, model, $isDeleted, remove, and 51 more.
tasks.service.ts
import { Injectable, HttpStatus } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Task } from './dto/task.inferface';
@Injectable()
export class TasksService {
private readonly Tasks: Task[] = [];
constructor(@InjectModel('Task') private readonly TaskModel: Model<Task>) {}
async getAll(): Promise<Task> {
const tasks = await this.TaskModel.find().exec();
return tasks;
}
}
【问题讨论】:
标签: mongodb typescript mongoose nestjs