I have a MongoDB server which has a NodeJS server to interact with it. I want Ember Store to get data from this server. A tutorial has led me until this point but it does not work for me (tutorial), I think it is outdated but I am not sure. This part of the backend server is about sending data:
app.get('/api/appointments', function(req, res){
AppointmentModel.find({}, function(err, docs){
if(err) res.send({error:err});
else res.send({data:docs, "type":"appointment"});
});
});
A curl request proves that it does work:
curl http://localhost:4500/api/appointments
{"data":[{"flags":[],"dates":[],"invited":[],"_id":"5adc8b6724a69f4327c4c7af","author":7,"title":"Does this work"}],"type":"appointment"}
This is the part of the ember code that makes the request to the server:
export default Route.extend({
model: function(){
return this.store.findAll('appointment');
}
});
This is the error I get in the console of the webbrowser(chrome):
Error while processing route: index Assertion Failed: Encountered a resource object with an undefined type (resolved resource using (unknown mixin)) Error: Assertion Failed: Encountered a resource object with an undefined type (resolved resource using (unknown mixin))
at new EmberError (http://localhost:4200/assets/vendor.js:24475:25)
at Object.assert (http://localhost:4200/assets/vendor.js:24725:15)
at Class._normalizeResourceHelper (http://localhost:4200/assets/vendor.js:85052:61)
at Class._normalizeDocumentHelper (http://localhost:4200/assets/vendor.js:84993:25)
at Class._normalizeResponse (http://localhost:4200/assets/vendor.js:85121:36)
at Class.normalizeArrayResponse (http://localhost:4200/assets/vendor.js:86013:19)
at Class.normalizeFindAllResponse (http://localhost:4200/assets/vendor.js:85873:19)
at Class.normalizeResponse (http://localhost:4200/assets/vendor.js:85816:23)
at normalizeResponseHelper (http://localhost:4200/assets/vendor.js:76037:39)
at promise.then.adapterPayload (http://localhost:4200/assets/vendor.js:76889:19)
Because the error is something about types I checked and checked again the models but did not find anything that would give an error. Ember:
export default DS.Model.extend({
author: DS.attr('number'),
title: DS.attr('string'),
description: DS.attr('string'),
flags: DS.hasMany('number'),
dates: DS.hasMany('date'),
invited: DS.hasMany('number')
});
NodeJS/Mongo:
//The schema for appointments
var appointmentSchema = new mongoose.Schema({
author: Number, //Userid of the owner of the appointment.
title: String,
description: String,
flags: [Number], //Array of ids of flags that are set.
dates: [Date],
invited: [Number] //Array of user ids.
});
var AppointmentModel = mongoose.model('appointment', appointmentSchema);
In what special way does ember need the data in order to correcly handle it?
I have read some docs about store and ember but I am still new to the framework, any help is much appreciated.
Aucun commentaire:
Enregistrer un commentaire