1
I’m using only find() on my server to Try to Retrieve data from Mongodb with Mongoose, but it retriveis this "{}", and on the console "Array(0) []"
js router.
const Teams = require('./models/map');
const request = require('request');
module.exports = function(app) {
app.get('/equipas', function(req, res) {
Teams.find({},(err, equipas) => {
if (err) {
res.status(500).send();
} else {
equipas.sort((a,b)=>{
return new Date(b.date) - new Date(a.date);
})
var array = [];
equipas.forEach((equipa)=>{
array.push({
id: equipa.id,
nome: equipa.nome,
Coach: equipa.Coach
})
})
console.log(array);
res.status(200).send(array);
}
});
});
};
map js.
// Dependências
var mongoose = require('mongoose');
module.exports = mongoose.model('Equipas', {
id : String,
nome : String,
jogadores: Array,
Coach: String
});