Like Query with Mongoid

Today I had to perform a like query with Mongoid (the popular MongoDB Object-Document-Mapper). Basically I wanted something like the familiar SQL query:

SELECT * FROM Users WHERE name LIKE ‘%bob%’

I couldn’t find anything similar in the Mongoid documentation, but according to the MongoDB documentation you can do regex searches.

User.where(name: /bob/)

Happy coding.