Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoose error on creating Model (using Step)
    primarykey
    data
    text
    <p>When trying to create a model in Mongoose I get the following error</p> <p>[TypeError: Cannot read property 'options' of undefined]</p> <p>I have no idea what's causing it</p> <pre><code>"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 }); //... } </code></pre> <p>I'm very new to Mongo (and fairly new to node) but I have absolutely no idea what the error message means.</p> <p>I know I have options defined in the schema but I cant see how it would be undefined, can anyone point me in the right direction?</p> <p>Note - this is a big cut out of the original code, this is the general structure (there's actually some code below <code>mongoose.Model('Cat...</code> but it gets skipped, I assume because the error is thrown by the <code>mongoose.Model</code> call as not even a <code>console.log("Hello");</code> is printed straight after it.</p> <p><strong>EDIT</strong> I've found that inside Mongoose (mongoose/lib/document.js) tries to get <code>this.schema</code> but it's undefined</p> <pre><code>function Document (obj, fields, skipId) { //Line 37 this.$__ = new InternalCache; this.isNew = true; this.errors = undefined; var schema = this.schema; //-&gt; undefined // ... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload