3

What is lazy loading in MongoDb? If we want to create a database, it is done like:

m.getDB(<dbName>).getCollectionNames() 

due to lazy loading only. Can anyone explain?

2
  • The question is unclear. Please give another example of what you want to know. And what does creating databases have to do with lazy loading? Commented Jun 22, 2011 at 5:12
  • 1
    This is answered here: stackoverflow.com/questions/3989791/… Hope you find the explanation useful. Thanks Commented Jun 22, 2011 at 5:16

2 Answers 2

7

Lazy loading is not something that is a capability of the database itself. All that it means is that when the client issues a query via a driver(or the ORM), the ORM can choose to not load the entire object graph when the query is made. It may choose to make the query to the db only when the resultant object is actually used/accessed.

This is again, independent of the databases that can be used, and is something that is typically built into the ORM itself. this is done for optimization/performance reasons, if a portion of the object graph is not always accessed, then it is fine if we lazy load it in the couple of instances when it Is actually accessed. Now this means that there will be a query that the ORM fires off to load that data on access, and then return the call to the client code.

It is typically unto the app developer to specify which properties/parts of the object graph should be loaded eagerly and which should be loaded lazily.

Now keep in mind that some nosql options may have ORM capabilities that enable us to do this, but th most common scenario where you will see this is in the RDBMS world, and where full blown ORMs are very common.

You can lookup hibernate's lazy load/lazy fetching capabilities to get abetter idea of the concept in general.

Sign up to request clarification or add additional context in comments.

1 Comment

ORM is a term for SQL Databases ONLY. Hibernate created OGM for document based databases.
0

Adding on to what Shekhar said, you need to do lazy loading in something like mongoose, which interfaces with MongoDB. I found a post here: Lazy Loading/More Data Scroll in Mongoose/Nodejs

Basically, using the Mongoose module, you can do something like this:

var lazyload = User.find().skip(10).limit(10);

This will take the User schema and load the second set of 10 elements (the limit function will limit the amount of objects loaded to 10 and the skip function is self-explanatory). In this way, you can increment how many objects you skip by to create a lazy-load system.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.