我如何附加文件在mongoose(模式)?当我使用字符串它的工作,但当使用文件的错误发生--[1]错误:未定义文件

xcitsw88  于 2022-11-13  发布在  Go
关注(0)|答案(1)|浏览(80)
const mongoose = require('mongoose');
const { Schema } = mongoose;

const NoteSchema = new Schema({
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'user',
  },
  title: {
    type: String,
    required: true,
  },

  description: {
    type: File, //for attachment of file (Error occurred here)
    required: true,
  },

  tag: {
    type: String,
    default: 'General',
  },
  date: {
    type: Date,
    default: Date.now,
  },
});

module.exports = mongoose.model('notes', NoteSchema);
yjghlzjz

yjghlzjz1#

正如我们可以在官方文档mongoose中读到的关于SchemaTypesMongoose版本6.6.4而不是File,我在SchemaTypes(docs)中找不到它。你应该使用BufferString,就像你上面提到的那样。当它涉及到文件和你上面的例子时,我也会使用source而不是description

相关问题