マイlocationsModel
ファイル:Mongooseモデルでメソッドを定義するにはどうすればよいですか?
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);
それを呼び出すために、私が使用しています:
myLocation.testFunc {locationText: locationText}, (err, results) ->
をしかし、私はエラーを取得する:
TypeError: Object function model() {
Model.apply(this, arguments);
} has no method 'testFunc'
申し訳ありませんが、私はここで誤読していますが、これはOPコードとどのように違うのか分かりません。 – Will
同じ方法を何とかmongoDBシェルを使って使用できますか? – p0lAris
@ウィル、私は違いがiZだと思う。モデルではなくスキーマに関数を適用しています。 – kim3er