Skip to content

Instantly share code, notes, and snippets.

@miligraf
Created February 26, 2012 01:28
Show Gist options
  • Save miligraf/1912066 to your computer and use it in GitHub Desktop.
Save miligraf/1912066 to your computer and use it in GitHub Desktop.
Mongoid version of SQL "SELECT * FROM Objects WHERE field1 LIKE '%search%' OR field2 LIKE '%search%'
search = params[:search][:text]
results = Object.any_of({ field1: /#{search}/ } , { field2: /#{search}/ })
@miligraf
Copy link
Author

Remember that MongoDB is case sensitive!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment