最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何将具有SchemaType选项的嵌套对象推入猫鼬模型?

IT培训 admin 15浏览 0评论

如何将具有SchemaType选项的嵌套对象推入猫鼬模型?

我的猫鼬模型:

const mongoose = require('mongoose');

const { Schema } = mongoose;

const VacancySchema = new Schema(
    {
        parameters: []
    },
    { timestamps: true },
    { strict: false }
);
      
module.exports = mongoose.model('Vacancy', VacancySchema);
回答如下:

您的Mongoose模式语法错误。我更正为;

const { Schema, model } = require('mongoose');

const VacancySchema = new Schema({
  parameters: [],
  timestamps: true,
  strict: false
});

const Vacancy = model('Vacancy', VacancySchema);

module.exports = Vacancy;

如何将具有SchemaType选项的嵌套对象推入猫鼬模型?

我的猫鼬模型:

const mongoose = require('mongoose');

const { Schema } = mongoose;

const VacancySchema = new Schema(
    {
        parameters: []
    },
    { timestamps: true },
    { strict: false }
);
      
module.exports = mongoose.model('Vacancy', VacancySchema);
回答如下:

您的Mongoose模式语法错误。我更正为;

const { Schema, model } = require('mongoose');

const VacancySchema = new Schema({
  parameters: [],
  timestamps: true,
  strict: false
});

const Vacancy = model('Vacancy', VacancySchema);

module.exports = Vacancy;
发布评论

评论列表 (0)

  1. 暂无评论