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

Viewed 1142

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?

1 Answers

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

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

Playground

Related