Morphia/MongoDB:如何迭代不同的字段
我想迭代给定文档中不同字段的列表。使用 MongoDB 命令行,我可以通过执行以下操作来获得我想要的东西:
db.MyDoc.distinct("someField")
...只不过它以巨大的 BSON 形式返回所有结果。
有没有办法在 Morphia 中做到这一点,并进一步将其作为 Iterable 返回,以便所有结果不会一次读入内存?
我认为 distinct()
是作为某种内存中哈希图实现的,这可能意味着我尝试逐步迭代结果以避免将它们全部放入内存中是没有意义的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使吗啡支持这一点,distinct 的结果仍然是单个 (bson) 文档,结果字段具有一组不同的值。基本上,它必须被完全读入内存。
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.
目前吗啡不支持此功能。有一个功能请求 http://code.google.com/p/morphia/issues/detail?id=219&colspec=ID%20Type%20Stars%20Status%20Priority%20Milestone%20Owner%20Summary 您可以观看。
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.