Meteor $and with $or

僤鯓⒐⒋嵵緔 提交于 2019-12-23 17:23:38

问题


I'm trying to do an $and and then $or in Meteor for my mongo query I have the following but it doesn't seem to be working

Would like the query to match documents where organizationId key has value in the variable user.organizationId AND where the type key is either 'converntional' or 'transition'

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

I can't use $not as I'm pretty sure it's not supported in Meteor. Right now the package I'm using does not support it.


回答1:


The following query describes what you are after as it uses the $in operator to match documents where the type key is either 'converntional' or 'transition'. The $and operator is implicitly provided when specifying a comma separated list of expressions. Using an explicit AND with the $and operator is only necessary when the same field or operator has to be specified in multiple expressions.

Would like the query to match documents where organizationId key has value in the variable user.organizationId AND where the type key is either 'converntional' or 'transition'

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


来源:https://stackoverflow.com/questions/30935591/meteor-and-with-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!