Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下内容:
User_Model.findAll( ("online" -> ("$gt" -> ( (System.currentTimeMillis() / 1000) - 60 )) )
我要做的是以某种方式定义将返回每条记录的哪些字段,而不是拉出整个对象。
在此先感谢您的帮助,非常感谢:)
我不知道电梯,但根据这个和这个你应该能够做这样的事情:
User_Model.findAll( qry = ("online" -> ("$gt" -> ((System.currentTimeMillis() / 1000) - 60))), keys = ("myfield" -> 1) )
以防万一有人在寻找参考,这就是我最终这样做的方式:
User_Model.findAll( ("online" -> ("$gt" -> ( (System.currentTimeMillis() / 1000) - 60) )), ( /* Field names */ ("uid" -> 1) ~ ("name" -> 1) ), Empty )
阅读基本文档有助于:
http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields
将其应用于任何语言或框架留给您作为练习。