【发布时间】:2014-12-05 02:55:41
【问题描述】:
我有以下 Mongoose 架构和路径验证:
var locationSchema = new Schema({
userid: { type: Number, required: true },
location: {
type: [{
type: "String",
required: true,
enum: ['Point', 'LineString', 'Polygon'],
default: 'Point'
}],
coordinates: { type: [Number], required:true }
},
tags: [{ type: String, index: true, required: true }],
create_date: { type: Date, default: Date.now }
});
locationSchema.path('location.coordinates').validate(function(coordinates){
return coordinates && coordinates.toString().match(/([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/g);
}, 'Invalid latitude or longitude.');
当我启动我的应用程序时,我得到:
locationSchema.path('location.coordinates').validate(function(coordinates){
^
TypeError: Cannot call method 'validate' of undefined
谁能告诉我为什么会失败?请注意,我只是验证路径('位置'),它开始正常。
【问题讨论】:
标签: node.js model mongoose typeerror