這是我locationsModel.js
文件:爲什麼我的Mongoose模型不能加載?
var LocationSchema, LocationsSchema, ObjectId, Schema, mongoose;
mongoose = require('mongoose');
Schema = mongoose.Schema;
ObjectId = Schema.ObjectId;
LocationSchema = {
latitude: String,
longitude: String,
locationText: String
};
LocationsSchema = new Schema(LocationSchema);
LocationsSchema.method({
getLocation: function(callback) {
return console.log('hi');
}
});
exports.Locations = mongoose.model('Locations', LocationsSchema, 'locations');
在我的控制,我有:
var Locations, mongoose;
mongoose = require('mongoose');
Locations = require('../models/locationsModel').Locations;
exports.search = function(req, res) {
var itemText, locationText;
Locations.getLocation('info', function(err, callback) {
return console.log('calleback');
});
return;
};
當我運行它,我得到以下錯誤:
TypeError: Object function model() {
Model.apply(this, arguments);
} has no method 'getLocation'
我是什麼失蹤?
在你的控制器,而不是'位置=需要( '../型號/ locationsModel')位置;'你可以簡單地去'Locations = mongoose.model('Locations')' –