Ceci est mon fichier locationsModel.js
:Pourquoi mon modèle Mongoose ne se charge-t-il pas?
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');
Dans mon contrôleur, j'ai:
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;
};
Quand je lance, je reçois l'erreur suivante:
TypeError: Object function model() {
Model.apply(this, arguments);
} has no method 'getLocation'
Que suis-je disparu?
Dans votre contrôleur au lieu de '= Emplacements require ('modèles ..//locationsModel') Emplacements,' vous pouvez simplement aller 'Locations = mongoose.model ('Locations')' –