这可能是一个愚蠢的问题,但是为什么我会收到以下代码片段的“意外 token ”错误?请记住,这是一个 Mongoose 模型。
错误消息
SyntaxError: D:/Coding/Species Project/backend/models/species.js: Unexpected token (15:2)
13 | },
14 | organism: {
> 15 | ...shared,
| ^
16 | enum: ["Plant", "Animal", "Other"],
17 | },
18 | taxonomy: {
Mongoose 模型
const shared = {
type: String,
required: true,
}
const SpeciesSchema = new Schema({
name: {
common: shared,
scientific: shared,
},
organism: {
...shared,
enum: ["Plant", "Animal", "Other"],
},
...,
}
最佳答案
扩展运算符用作数组的参数。
您可能想使用它
const SpeciesSchema = new Schema({
name: {
common: shared,
scientific: shared,
},
organism: Object.assign({}, shared, enum: ["Plant", "Animal", "Other"]},
...,
}
关于javascript - 为什么我无法在我的 Mongoose 模型中传播对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48936440/