当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
    // ...

推荐答案

所以我不是那种善于观察的人,

mongoose.Model应该是mongoose.model

Mongodb相关问答推荐

在MongoDB查询中添加来自另一个集合的匹配文档的计数

如何联接Mongoose中的集合并检索特定字段

Mongo查找条件:不存在

MongoDB 使用 pymongo 收集 500K 文档的写入速度很差

MongoDB - 在 $lookup 管道中匹配键匹配不起作用

有谁知道这个错误的修复方法(TypeError: Cannot assign to read only property ‘map’ of object '#')

Mongo C#忽略属性

如何使用 C# MongoDB 驱动程序检索字段子集?

MongoDB 2.1 聚合框架总和匹配名称的数组元素

使用 mgo 存储嵌套 struct

如何使用 java 驱动程序更新 mongo db 中的文档字段?

带有 Java 驱动程序的 MongoDB 聚合

在 mongodb 中的索引列上查找重复项的快速方法

MongoDB 范围查询中 $lt 和 $gt 的顺序

在 mongodb 中插入当前日期时间

如何从 Mongoose 模型对象中获取集合名称

如何在 NoSql 数据库(MongoDB)中强制执行外键?

如何通过mongoose更新 mongodb 中的对象?

Mongodb 按字段名称查找任何值

Mongodb Compass 无法在 Ubuntu 18.10 中打开