【问题标题】:typegoose/mongoose What is correct way to get new document from model classtypegoose/mongoose 从模型类获取新文档的正确方法是什么
【发布时间】:2021-12-01 21:35:05
【问题描述】:

我将 mongoose 版本升级到 6 后发现...

import {
    getModelForClass,
} from "@typegoose/typegoose";

export const ProductModel = getModelForClass(Product); // this give me mongoose model type from my class



const product = new Product();

const A = new ProductModel(product) // A is not DocumentType it is just Product...
const B = new ProductModel({...product}) //  B is DocumentType But why?

  1. 您能解释一下这是如何工作的吗?
  2. 获取 DocumentType 实例的正确方法是什么?
  3. 我想搜索 Mongoose 文档,但找不到合适的关键字。你能给我一个链接和提示吗..

【问题讨论】:

    标签: node.js database mongodb mongoose typegoose


    【解决方案1】:

    这个问题也在Github Discussions 中提出并在那里解决

    TL;DR:这个不同类型的问题似乎来自 typescript 4.3,升级到 typescript 4.4 解决了它

    【讨论】:

      猜你喜欢
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多