0 votes
1 view
in Web Technology by (29k points)

My locationsModel file:

mongoose = require 'mongoose'

threeTaps = require '../modules/threeTaps'

Schema = mongoose.Schema

ObjectId = Schema.ObjectId

LocationSchema =

  latitude: String

  longitude: String

  locationText: String

Location = new Schema LocationSchema

Location.methods.testFunc = (callback) ->

  console.log 'in test'

mongoose.model('Location', Location);

To call it, I'm using:

myLocation.testFunc {locationText: locationText}, (err, results) ->

But I get an error:

TypeError: Object function model() {

    Model.apply(this, arguments);

  } has no method 'testFunc'

1 Answer

0 votes
by (64k points)

Here's how you'd define a class/static method:

animalSchema.statics.findByName = function (name, cb) {

    return this.find({ 

        name: new RegExp(name, 'i') 

    }, cb);

}

Related questions

0 votes
2 answers
0 votes
2 answers
0 votes
1 answer
0 votes
2 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...