Almog
Almog

Reputation: 2837

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.

Upvotes: 3

Views: 1251

Answers (1)

chridam
chridam

Reputation: 103455

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'] 
    }
}

Upvotes: 3

Related Questions