猫鼬显示ID仅为零

时间:2020-07-21 03:17:06

标签: node.js mongoose

我实际上是在定义这种猫鼬模型:

import mongoose, {Schema} from "mongoose";
import {mongoosePagination} from "ts-mongoose-pagination";
import autoPopulate = require('mongoose-autopopulate');
import {IForum} from "../../interfaces/forum/IForum";
import forumWare from "./middleware/forum";

const Forum = new mongoose.Schema(
    {
        name: {
            type: String,
            index: true,
            required: true
        },
        order: {
            type: Number,
            default: 0
        },
        description: {
            type: String,
            default: ''
        },
        category: {
            type: Schema.Types.ObjectId,
            ref: 'ForumCategory',
            required: true,
            autopopulate: true
        },
        parent: {
            type: Schema.Types.ObjectId,
            ref: 'Forum',
            autopopulate: true
        },
        guest: {
            type: Boolean,
            default: false
        }
    },
    { timestamps: true }
);


Forum.plugin(mongoosePagination);
Forum.plugin(autoPopulate);
export default mongoose.model<IForum & mongoose.Document>('Forum', Forum);

但是当我尝试通过任何猫鼬查询获得一项时,我得到的ObjectId为:ObjectId(“ 00000000000000”)。

我想知道是否有人知道原因。存储在MongoDB上的模型是正确的,只有ID怪异的猫鼬的响应才是正确的。

0 个答案:

没有答案