Using Lithiums Model, how do you achieve getting a distinct result set of specific fields from a collection in MongoDB?
mongo query:
db.blogs.distinct('url');
私の知る限り、これをエレガントに行う方法は現在ありません。Pecl MongoDBオブジェクトを直接操作することで、結果を得ることができます。このcommand
関数を使用すると、任意の呼び出しを行うことができます。
$db = Connections::get('default');
$blogs = $db->connection->command(array('distinct'=>'blogs', 'key'=>'url'));