Sha*_*oon 2 mongodb mongomapper ruby-on-rails-3
如何使用MongoMapper 查询distinct?我的查询是:
subscribedToThread = Comment.where(:subscribe_thread => 1).all
但这将返回许多具有相同的对象user_id.我需要回报一个截然不同的user_id.这可能吗?
我认为您需要下载到ruby驱动程序才能执行此操作,因为我认为您无法使用MongoMapper本身执行此操作:
subscribedToThread = Comment.collection.distinct("user_id", {:subscribe_thread => 1})
Run Code Online (Sandbox Code Playgroud)
在模型上调用集合方法会返回Ruby驱动程序直接提供的集合,因此您可以使用以下语法发出不同的查询:
collection.distinct(key, query = nil)
你可以在这里阅读更多相关信息
| 归档时间: |
|
| 查看次数: |
1494 次 |
| 最近记录: |