Root
Root

Reputation: 147

Mongodb search special character (\) in a collection

How to search strings starting with '\' in mongodb. Please help

db.txt.insert({"name": "\paul"})
db.txt.insert({"name": "Oracle"})
db.txt.insert({"name": "\Testing program"})

Output required:

\paul
\testing program

Upvotes: 2

Views: 6699

Answers (1)

Sede
Sede

Reputation: 61225

You need to use the $regex operator.

db.txt.find({ "name": { "$regex": /^\\/ }})

Upvotes: 4

Related Questions