Wie definiere ich Methoden in einem Mongoose-Modell?

Meine locationsModel Datei:

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);

Nennen es, ich bin mit:

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

Aber ich bekomme eine Fehlermeldung:

TypeError: Object function model() {
    Model.apply(this, arguments);
  } has no method 'testFunc'

InformationsquelleAutor der Frage Shamoon | 2011-09-14

Schreibe einen Kommentar