开发者

Morphia/MongoDB: how to iterate over distinct fields

I'd like to iterate over a list of distinct fields in a given document. Using the MongoDB command line, I can kind of get what I want by doing something like:

db.MyDoc.distinct("someField")

... except that it returns all the results as a giant BSON.

Is there a way to do this in Morphia, and to furthermore return it as an Iterable, so that all the results are not read into memory all at once?

I imagine that distinct() is implemented as some kind 开发者_如何学编程of in-memory hashmap, which probably means that there's no point in my trying to iterate over the results piecemeal to avoid having them all in memory at once.


Even when this is supported by morphia the result of distinct is still a single (bson) document, with an array of distinct values for the result field. It will have to be read completely into memory, basically.


this is not supported in morphia currently. There is a feature request http://code.google.com/p/morphia/issues/detail?id=219&colspec=ID%20Type%20Stars%20Status%20Priority%20Milestone%20Owner%20Summary you can watch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜