I have a MongoDB database with 10-12k documents in the collection, and I get very slow queries when trying to get all the documents, for example:
Sales.find()
.where('author').equals(author)
.where('date').gt(startDate.unix()).lt(endDate.unix())
.exec(function(err, results) {
callback();
});
This request retrieves about 10.5 thousand documents, and it takes 1000-1300 ms to complete it. I tried to remove the "where" conditions - it only slows down (more documents delivered?).
Does the problem come from Mongoose, MongoDB, JavaScript, or Node? I used the PHP / MySQL database, and it was 10-20 times faster in similar conditions, for example, fetching 10k + rows of data. What am I doing wrong?
EDIT
Sales Scheme:
var salesSchema = new Schema({
author: String,
kind: String,
productID: String,
description: String,
date: String,
amount: String,
transactionID: {
type: String,
unique : true
}
});
The result of a request from the RoboMongo desktop client:
db.getCollection('sales').find({}).explain()
executionTimeMillis: 46
nReturned: 10359