TypeScript- 自定义对象 ID 而不是默认 MongoDB 对象 ID

TypeScript- Custom Object ID instead of Default MongoDB Object ID

我正在使用 Typescript 从 MongoDB 获取默认的 MongoDB 对象 ID。如何获取自定义 ID 而不是默认的 MongoDB 对象 ID?

{ "_id": "5bbe053ab10bdf08964443d5", "title": " Moto Z", "manufacture_details": { "brand": "Motorola", "model_number": "XT1650" } }

这是我的Model.ts

import * as mongoose from 'mongoose';

const Schema = mongoose.Schema;

export const ProductSchema = new Schema({
    title: {
        type: String,
    },
    manufacture_details: {
        brand: String,
        model_number: String,
      },
});

我用新字段 _id 更新了 Model.ts,它将覆盖默认的对象 ID

import * as mongoose from 'mongoose';

const Schema = mongoose.Schema;

export const ProductSchema = new Schema({
    _id: {
        type: String,
    },
    title: {
        type: String,
    },
    manufacture_details: {
        brand: String,
        model_number: String,
      },
});

现在我可以获取自定义对象 ID

{ "_id": "M01", "title": " Moto Z", "manufacture_details": { "brand": "Motorola", "model_number": "XT1650" } }