Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB: How Find the document where their name starts with “S” and “R”?

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?

like image 306
Lightning21Cheetah Avatar asked Nov 03 '25 07:11

Lightning21Cheetah


1 Answers

You can use | pipe sign to put or condition in regex,

db.employees.find({
  Name: /^S|^R/
})

Playground

like image 154
turivishal Avatar answered Nov 06 '25 02:11

turivishal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!