Rocky Pulley
Rocky Pulley

Reputation: 23301

Mongoose count query with mutliple fields ORed

I want to find a count of all documents with a title or desc field that contains my search string. I have tried the following and it always just returns all rows, ignoring the filter.

FCSet.count([{ 'title': { $regex: re }}, { 'desc': { $regex: re }}]).exec(function(err, count) {
}

I can do them one at a time, if I include just title it works just fine.

Upvotes: 0

Views: 75

Answers (1)

heinob
heinob

Reputation: 19464

Try this:

FCSet.count( 
    {
        $or: [
            { 'title': { $regex: re } }, 
            { 'desc': { $regex: re } } 
        ]
    }
).exec( function( err, count ) {}

Upvotes: 1

Related Questions