简体   繁体   中英

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() ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM