首页 > 解决方案 > 如何在 Typescript 接口中存储 objectID 属性?

问题描述

我在 Typescript 中实现接口和猫鼬模式。与以下问题的斗争:

Schema 应该包含以下属性:

let MovementSchema = new Schema
    ({
        movementName : {type: mongoose.Schema.Types.ObjectId, ref: 'MovementName'},
        rounds: [{type: mongoose.Schema.Types.ObjectId, ref: 'Round'}]
    });

界面如下所示:

import { ObjectId } from "bson";

export interface IMovement {
    movementType : ObjectId,
    rounds : [ ObjectId ]
}

问题是,ObjectId创建属性的好类型是什么?

标签: typescriptmongooseinterface

解决方案


而不是ObjectId它应该存储为string.


推荐阅读