Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor $and with $or

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.

like image 242
Almog Avatar asked Nov 29 '25 11:11

Almog


1 Answers

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'] 
    }
}
like image 84
chridam Avatar answered Dec 01 '25 09:12

chridam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!