2017-04-26 28 views
0

我想限定日提交的「行」作爲值的陣列,其可以是不同類型(數字或字符串或布爾或日期)Mongoose數據類型如何定義多個類型值? ESLint錯誤

當我嘗試的:

lines: [ 
{ 
    type: String, 
    content: Mixed 
} 

]

我得到一個錯誤ESLint錯誤:混合沒有定義

我應該寫?

const Schema = mongoose.Schema; 
... 
lines: [ 
    Schema.Types.Mixed 
] 
+0

使用混合模式類型,我認爲應該型混合 –

回答

1

據貓鼬documentation您可以按如下

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); 
+0

非常感謝......它的工作原理.. – erwin