Both Morphia and MongodD开发者_运维问答B 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.
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.
精彩评论