开发者

Morphia/MongoDB: how to iterate over distinct fields

开发者 https://www.devze.com 2023-02-11 17:39 出处:网络
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:

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

精彩评论

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

关注公众号