In Mongodb compass. I want to search a collection for the word "LLC" in Both the ownerName and ownerStreet properties (I don't have a text index.) I started with :
{ownerName: {$regex: / LLC/i}}
which gives 3043 results.
However using:
{ownerName: {$regex: RegExp(' LLC')},ownerStreet: {$regex: RegExp(' LLC')}}
gives only 100
meaning this is an 'and' statement not an 'or'
How do I use an 'or' statement filter in compass?
You can use the $or
operator.
db.collection.find({
$or: [
{
ownerName: { $regex: RegExp(' LLC') }
},
{
ownerStreet: { $regex: RegExp(' LLC') }
}
]
})
You can even simplify it to
db.collection.find({
$or: [
{
ownerName: / LLC/
},
{
ownerStreet: / LLC/
}
]
})