I have been working with mongoose for a while, and I'm currently stuck with this problem:
I have a dynamic MongoDB database on which express-end batch inserts records using Model.collection.insert. The insert is perfect, I see all the documents on demand using the mongo shell, and the number of documents is as expected.
Here is the format of the inserted documents:
[
{
"disk":"Aff90",
"graph":
{
"Q1":{
"frequency":21
},
"Q2":{
"frequency":13
},
"Q3":{
"frequency":35
},
"Q4":{
"frequency":24
}
},
"sales": 987,
"deep_discount": 50,
"demand_score": 3.4
},
{
"disk":"B721",
"graph":
{
"Q1":{
"frequency":98
},
"Q2":{
"frequency":129
},
"Q3":{
"frequency":812
},
"Q4":{
"frequency":240
}
},
"sales": 2017,
"deep_discount": 80,
"demand_score": 7.4
},//and so on(about 1000 documents)
]
However, when I use my express point to request this data, it returns only the first element. I have not encountered this specific problem with mongoose yet and could not find a solution on the Internet.
Express API to retrieve:
router.post('/end-point', function(req, res, next) {
model.find({}, {"_id":0}, function(err, data){
if(err){
throw err;
}
if(data.length){
res.json(data);
}
});
});
Can someone help me understand what the problem is and how can I solve it?