简体   繁体   English

锂mongodb带条件的不同命令

[英]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 ): 在锂模型中,我可以使用command()选择特定字段的唯一性(请参见锂中的distinct selects ):

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

which is translated to mongodb command as: 转换为mongodb命令为:

db.blogs.distinct('url');

Now I want to add a condition on type='rumours' in my distinct query: 现在,我想在不同的查询中为type ='rumours'添加条件:

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

How do I add this {type: 'rumours'} condition in command() ? 如何在command()添加此{type: 'rumours'}条件?

The optional argument in the shell method is a "query" document, so if you follow the distinct command documentation: shell方法中的可选参数是一个“查询”文档,因此,如果您遵循不同的命令文档:

$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. 因此,这里唯一缺少的是您要发送的命令文档中的“查询”键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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