【问题标题】:Meteor $and with $or流星 $and 与 $or
【发布时间】:2015-06-19 10:14:38
【问题描述】:

我正在尝试为我的 mongo 查询在 Meteor 中执行 $and 然后 $or 我有以下内容,但它似乎不起作用

希望查询匹配organizationId 键在变量user.organizationId 中具有值且类型键为“converntional”或“transition”的文档

{
    organizationId: user.organizationId,  
    $and:[
       { $or:[
           {type: 'conventional'},
           {type: 'transition'}
       ]}
   ]
}; 

我不能使用 $not,因为我很确定 Meteor 不支持它。现在我使用的包不支持它。

【问题讨论】:

  • $and 基本上什么都不做,因为它后面只有一个子句。结果应该是什么,用英语表达?
  • 我觉得你需要$in如下{organizationId:user.organizationId, type: { $in : ['conventional', 'transition'] }}
  • @deceze 给出所有与 organizationId 匹配并且必须具有常规或过渡类型的 X 集合
  • @chridam 我以为 $in 只是用于数组?
  • @chridam $in 不起作用

标签: mongodb meteor mongodb-query


【解决方案1】:

以下查询描述了您所追求的内容,因为它使用 $in 运算符来匹配类型键为 'converntional''transition' 的文档。 $and 运算符在指定以逗号分隔的表达式列表时隐式提供。仅当必须在多个表达式中指定相同的字段或运算符时,才需要对 $and 运算符使用显式 AND。

希望查询匹配 organizationId 键所在的文档 变量 user.organizationId 中的值 AND 类型键在哪里 “转换”或“过渡”

{
    organizationId: user.organizationId, 
    type: { 
        $in : ['conventional', 'transition'] 
    }
}

【讨论】:

  • $in 正是我想要的,完美,谢谢。
猜你喜欢
  • 1970-01-01
  • 2011-07-14
  • 1970-01-01
  • 2017-08-05
  • 2013-04-07
  • 1970-01-01
  • 2012-10-10
  • 2013-05-23
  • 2015-01-17
相关资源
最近更新 更多