当try 在Mongoose中创建模型时,我得到以下错误
[TypeError:无法读取未定义的属性'options']
我不知道是什么原因
"use strict";
var Step = require('step');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
function randomFunction() {
var categorySchema = new Schema({
id: Number,
name: String,
description: String
}, { collection: 'categories' });
var Category;
//...
mongoose.connect('mongodb://localhost/grouping');
new Step(
function() { //Connect to mongodb
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.on('open', this);
},
function() { //Create model
console.log(categorySchema); //Logs the schema object right
Category = mongoose.Model('Category', categorySchema);
},
function(err) {
console.log(err); //Error here
});
//...
}
我对Mongo非常陌生(对node也相当陌生),但我完全不知道错误消息的含义.
我知道我在模式中定义了选项,但我看不出它是如何未定义的,有人能给我指出正确的方向吗?
注意——这是原始代码的一个大片段,这是一般 struct (实际上有些代码低于mongoose.Model('Cat...
,但它被跳过了,我假设是因为错误是由mongoose.Model
调用引发的,因为在它之后甚至没有直接打印console.log("Hello");
).
EDIT
function Document (obj, fields, skipId) { //Line 37
this.$__ = new InternalCache;
this.isNew = true;
this.errors = undefined;
var schema = this.schema; //-> undefined
// ...