Trying to create a model, but I get an error when running the code

9 views
Skip to first unread message

Giles Peng

unread,
Mar 28, 2016, 4:09:19 PM3/28/16
to Mongoose Node.JS ODM
Hi,

  I'm trying to use Mongoose to model a book.  But I get 

var bookModel = new Schema({

                ^

TypeError: object is not a function


This is my model code:


var mongoose = require('mongoose');

var Schema = mongoose.Schema();


var bookModel = new Schema({

title: {

type: String

}, 

author: {type: String},

genre: {type: String},

read: {type: Boolean, default: false}

});


module.exports = mongoose.model('Book', bookModel);


Why am I getting a object is not a function error?


Thanks,

Giles

A

unread,
Mar 29, 2016, 4:58:11 PM3/29/16
to Mongoose Node.JS ODM
default: false
vs
default: Boolean

Jason Crawford

unread,
Mar 29, 2016, 5:01:32 PM3/29/16
to mongoo...@googlegroups.com
Because you're trying to invoke an object like a function.

I think it's because of this line:

var Schema = mongoose.Schema();

Why are you doing that?

-Jason


--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Fieldbook: Create a database, as easily as a spreadsheet

Giles Peng

unread,
Mar 29, 2016, 6:05:23 PM3/29/16
to mongoo...@googlegroups.com
Wasn't paying attention and added the ().  That solved it.

Thanks.

You received this message because you are subscribed to a topic in the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongoose-orm/TuUDupZnpMU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongoose-orm...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages