Reputation: 51
I use this manually db.employees.find({Name: /^S/});
and db.employees.find({Name: /^R/});
to find the starts letter of "S" and "R",
is their any way to use the two starts letter in one function?
Upvotes: 4
Views: 5706
Reputation: 1
This explicitly uses the $regex operator. It searches for all names that start with "S". It is a more flexible approach because you can add additional regex options like case insensitivity ($options: 'i').
db.Employees.find({name: {$regex: /^S/}});
and
db.Employees.find({name: {$regex: /^s/, $options: 'i'}});
Upvotes: 0
Reputation: 36134
You can use |
pipe sign to put or condition in regex,
db.employees.find({
Name: /^S|^R/
})
Upvotes: 7