Kushal Shah
Kushal Shah

Reputation: 55

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 ?

Upvotes: 4

Views: 6280

Answers (2)

rAJesh
rAJesh

Reputation: 1

Try to get the subset which is needed. If you try to fetch all objects, then it is for sure you will need enough RAM as the size of your database collection !! Try to fetch the objects which will be used in the application.

Upvotes: 0

jgauffin
jgauffin

Reputation: 101192

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

Upvotes: 4

Related Questions