PMXBOT Log file Viewer

Help | Karma | Search:

#mongodb logs for Monday the 24th of August, 2020

(Back to #mongodb overview) (Back to channel listing) (Animate logs)
[12:28:01] <bluezone> I have a collection with more than 1 million records. Each document has a Date field "createdAt". I need to get the 10 most recently created records. So I added an index on createdAt `Records._ensureIndex({ createdAt: -1})`. So I sort them by createdAt (in descending order) and fetch the first 10 records after the sorting is done. The issue is, even with the index, this is taking 30 seconds - 1 minute, which is too
[12:28:01] <bluezone> long. Is there a better way to go about this?
[17:57:12] <c4017w_> How to use the subfield of a generated object in aggregate? Like {$arrayElemAt: ['$TestResults', 1]}.result
[17:57:37] <c4017w_> arrayElemAt returns an object in this case, can I get .result directly without storing the object first?