Aly Dawood
Aly Dawood

Reputation: 1

MongoDB combining $and and $or

select * 
from job 
where 
    (title LIKE %xxx% OR dsc LIKE %xxx% OR requirements LIKE %xxx% ) 
    AND 
    (country LIKE %xxx%)

How can I do this in MongoDB?

Upvotes: 0

Views: 53

Answers (1)

Mohsen ZareZardeyni
Mohsen ZareZardeyni

Reputation: 956

use this:

db.job.find({
    $and : [
        {$or : [
            {title  : \xxx\},
            {dsc : \xxx\},
            {requirements : \xxx\}
        ]},
        {country : \xxx\}
    ]
})

Upvotes: 1

Related Questions