anhlc
anhlc

Reputation: 14469

Lithium mongodb distinct command with conditions

In lithium models, I can use the command() to select distinct of specific field (See distinct selects in lithium):

$blogs = $self->connection->command(array('distinct'=>'blogs', 'key'=>'url'));

which is translated to mongodb command as:

db.blogs.distinct('url');

Now I want to add a condition on type='rumours' in my distinct query:

db.blogs.distinct('url', {type: 'rumours'});

How do I add this {type: 'rumours'} condition in command()?

Upvotes: 0

Views: 145

Answers (1)

Neil Lunn
Neil Lunn

Reputation: 151122

The optional argument in the shell method is a "query" document, so if you follow the distinct command documentation:

$blogs = $self->connection->command(
    array('distinct'=>'blogs', 'key'=>'url', 'query' => array( 'type' => 'rumours' ) )
);

So the only thing missing here is the "query" key in the command document you are sending.

Upvotes: 3

Related Questions