S
S
Stanislav2017-07-06 11:57:05
MongoDB
Stanislav, 2017-07-06 11:57:05

How to find data by one or more matches?

There are documents like

{
    count: {
        day: {
            s: 10,
            g: 0
        }
    }
}

Need to find a document in which the count.day.s OR count.day.g fields are greater than zero
I am writing a query
Users
    .findOne({
        $or: [{
            'count.day.s': {
                $gt: 0
            },
            'count.day.g': {
                $gt: 0
            }
        }]
    }, (e, d) => {
    
    console.log(d); // null
    
});

Outputs null, but there is one document which has count.day.s = 50
What's the problem? What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2017-07-06
@ms-dred

Skobochek did not report:

db.test.findOne({$or: 
  [
    {'count.day.s': {$gt: 0}},
    {'count.day.g': {$gt: 0}}
  ]
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question