Mongoose 数据类型如何定义多个类型值?ESLint 错误

4 mongoose node.js eslint

我想将归档的“行”定义为可以是不同类型的值数组(数字或字符串或布尔值或日期)

当我尝试时:

lines: [
{
  type: String,
  content: Mixed
}
Run Code Online (Sandbox Code Playgroud)

]

我收到 ESLint 错误错误:未定义混合

我应该写吗?

 const Schema = mongoose.Schema;
 ...
 lines: [
   Schema.Types.Mixed
 ]
Run Code Online (Sandbox Code Playgroud)

Osa*_*ama 7

根据 mongoose文档,您可以使用混合模式类型,如下所示

var schema = new Schema({
ofMixed:    [Schema.Types.Mixed],
})

// example use

var Thing = mongoose.model('Thing', schema);

m.ofMixed = [1, [], 'three', { four: 5 }];
m.save(callback);
Run Code Online (Sandbox Code Playgroud)