我仅在服务器上使用find()尝试使用mongoose从MongoDB检索数据,但它会在控制台{}
和控制台Array(0) []
router.js
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
//Dependencies
var mongoose = require('mongoose');
module.exports = mongoose.model('Equipas', {
id : String,
nome : String,
jogadores: Array,
Coach: String
});