ace
ace

Reputation: 12024

What is the performance difference between Morphia and MongoDB Module in Play framework?

Both Morphia and MongodDB Module in play framework are wrappers around Java driver for MongoDB.

But I noticed Morphia does not give directly a Java List when querying. It gives me a complex object called Query. On this object I have to call method asList() which causes it to iterate over each element in Query and generate a List. I think this can have performance impact when most of the time I need Java lists. I wonder why Morphia does not generate List at the time it fetches data from mongodb database.

Upvotes: 3

Views: 1131

Answers (1)

Pere Villega
Pere Villega

Reputation: 16439

The reason is that it lets you decide how you want your data. As seen in the wiki you could only retrieve the first object via get(), or a list of id via asKeyList(). They acknowledge that using as List() can be costly for large sets.

The reason behind, for what I understand, is reusing the Query object. They let you build a complex Query object (with filters and such) and retrieve the results when required. You could even retrieve different sets of results from the same Query, as the listed methods (asList, etc) don't impact the query object.

If you will reuse your query objects a lot, and you won't return huge sets of data (which you shouldn't do too happily anyway) this can be useful.

Upvotes: 3

Related Questions