Methods and Statics not working

1,301 views
Skip to first unread message

daniel

unread,
Sep 18, 2011, 12:38:45 PM9/18/11
to Mongoose Node.JS ORM
Hi all,

today I played a bit with Mongoose but the Methods and Statics did not
work.

I get this error every time I want to access Statics/Methods:

node.js:134
throw e; // process.nextTick error, or 'error' event on
first tick
^
TypeError: Object function model() {
Model.apply(this, arguments);
} has no method 'test'

I tested this way: http://mongoosejs.com/docs/methods-statics.html
and this: https://github.com/LearnBoost/mongoose/blob/master/docs/methods-statics.md

But both failed.

I am using Mongoose 2.1.3 with Node v0.4.8.

TylerS

unread,
Sep 19, 2011, 12:58:35 PM9/19/11
to mongoo...@googlegroups.com
Make sure you're using the methods / statics on a model, and not a schema. You will get that error if you're trying to call the method directly on the schema, before creating the mongoose model.


var schema = new Schema();

schema.static('test',function() { return 'Hello world'; });

var model = mongoose.model('modelName',schema);

model.test() //Hello world

daniel

unread,
Sep 19, 2011, 2:43:20 PM9/19/11
to mongoo...@googlegroups.com
Ah ok I found my mistake: 
I created my schema in an external file and forgot to pass the schema object at the model.

Thanks for your help!

--
http://mongoosejs.com
http://github.com/learnboost/mongoose
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en

Reply all
Reply to author
Forward
0 new messages