1

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');
4

1 に答える 1

3

私の知る限り、これをエレガントに行う方法は現在ありません。Pecl MongoDBオブジェクトを直接操作することで、結果を得ることができます。このcommand関数を使用すると、任意の呼び出しを行うことができます。

$db = Connections::get('default');
$blogs = $db->connection->command(array('distinct'=>'blogs', 'key'=>'url'));
于 2011-05-22T18:06:48.993 に答える