Sam*_*Sam 21 mongoose mongodb node.js
当尝试在Mongoose中创建模型时,我收到以下错误
[TypeError:无法读取未定义的属性'选项']
我不知道是什么导致了它
"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
});
//...
}
Run Code Online (Sandbox Code Playgroud)
我是Mongo的新手(对于节点来说还是新手),但我完全不知道错误信息是什么意思.
我知道我在模式中定义了选项,但是我不知道它是如何被定义的,有人能指出我正确的方向吗?
注意 - 这是原始代码的一个重要部分,这是一般结构(下面实际上有一些代码,mongoose.Model('Cat...
但它被跳过,我假设因为错误是由mongoose.Model
调用引发的,因为甚至没有console.log("Hello");
直接打印它.
编辑
我发现在Mongoose内部(mongoose/lib/document.js)尝试获取this.schema
但是它未定义
function Document (obj, fields, skipId) { //Line 37
this.$__ = new InternalCache;
this.isNew = true;
this.errors = undefined;
var schema = this.schema; //-> undefined
// ...
Run Code Online (Sandbox Code Playgroud)
Sam*_*Sam 77
事实证明我不是观察者,
mongoose.Model
应该 mongoose.model