在我的架构中,如果我有 options
在 metrics : [ { options : {} } ]
那么我得到:
/home/one/cloudimageshare-monitoring/project/node_modules/mongoose/lib/schema.js:282
throw new Error("`" + path + "` may not be used as a schema pathname");
^
Error: `options` may not be used as a schema pathname
但是,如果将 options
更改为任何其他单词...例如 qoptions
...。那么错误就会消失。为什么会这样?
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var FilesystemSchema = new mongoose.Schema({
timeStamp : { type : Date, index: true },
avaiable : Boolean,
status : String,
metrics : [
{ options : {
data : String,
type : String,
unit : String
}
},
{ freeFiles : {
data : Number,
type : String,
unit : String
}
},
{ total : {
data : Number,
type : String,
unit : String
}
},
{ avail : {
data : Number,
type : String,
unit : String
}
},
{ free : {
data : Number,
type : String,
unit : String
}
},
{ files : {
data : Number,
type : String,
unit : String
}
},
{ used : {
data : Number,
type : String,
unit : String
}
}
]
});
module.exports = FilesystemSchema;
最佳答案
Mongoose 有许多不能使用的 Reserved
架构名称,以避免与 Mongoose 的内部实现发生冲突。该列表来自 docs保留以下内容:
on, emit, _events, db, get, set, init, isNew, errors, schema, options, modelName, collection, _pres, _posts, toObject
在您的架构中应避免使用这些术语!
关于node.js - 奇怪的 Mongoose schema.js 错误 - `options` 不能用作模式路径名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24130600/