I am currently using MongoDB cursor\'s toArray() function to convert the database results into an array:
run = true;
count = 0;
var start = process.hrtime();
db.collection.find()
returns a cursor, not results, and opening a cursor is pretty fast.
Once you start reading the cursor (using .toArray()
or by traversing it using .each() or .next()), the actual documents are being transferred from the database to your client. That operation is taking up most of the time.
I doubt that using .each()/.next()
(instead of .toArray()
, which—under the hood—uses one of those two) will improve the performance much, but you could always try (who knows). Since .toArray()
will read everything in memory, it may be worthwhile, although it doesn't sound like your data set is that large.
I really think that MongoDB on Raspberry Pi (esp a Model 1) is not going to work well. If you don't depend on the MongoDB query features too much, you should consider using an alternative data store. Perhaps even an in-memory storage (500 documents times 4 numbers doesn't sound like lots of RAM is required).