node.js - Mongoose error on creating Model (using Step) -
when trying create model in mongoose following error
[typeerror: cannot read property 'options' of undefined]
i have no idea what's causing it
"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 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 schema object right category = mongoose.model('category', categoryschema); }, function(err) { console.log(err); //error here }); //... }
i'm new mongo (and new node) have absolutely no idea error message means.
i know have options defined in schema cant see how undefined, can point me in right direction?
note - big cut out of original code, general structure (there's code below mongoose.model('cat...
gets skipped, assume because error thrown mongoose.model
call not console.log("hello");
printed straight after it.
edit i've found inside mongoose (mongoose/lib/document.js) tries this.schema
it's undefined
function document (obj, fields, skipid) { //line 37 this.$__ = new internalcache; this.isnew = true; this.errors = undefined; var schema = this.schema; //-> undefined // ...
so turns out i'm not observent kind,
mongoose.model
should mongoose.model
best post.thanks for shared
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course | Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Training in Pune | Certification | Online Training Course | Full Stack Training | Certification | Full Stack Online Training Course