Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo DB - fastest way to retrieve 5 Million records from a collection

I am using MongoDB in our project and I'm currently learning how things work

I have created a collection with 5 million records. When i fire the query db.ProductDetails.find() on the console it takes too much time to display all the data.

Also when i use the following code in C#

var Products = db.GetCollection("ProductDetails").FindAll().Documents.ToList();

the system throws OutOfMemoryException after some time..

Is there any other faster or more optimized way to achieve this ?

like image 982
Kushal Shah Avatar asked Sep 19 '25 19:09

Kushal Shah


1 Answers

Never try to fetch all entries at the same time. Use filters or get a few rows at a time.

Read this question: MongoDB - paging

like image 187
jgauffin Avatar answered Sep 21 '25 18:09

jgauffin