mongox_ecto v0.2.0 Mongo.Ecto.Regex
An Ecto type to represent MongoDB’s Regex objects
Both MongoDB and Elixir use PCRE (Pearl Compatible Regular Expressions), so the syntax is similar for both.
Using in queries
MongoDB supports two ways to use regexes.
One is to use regex object:
regex = Mongo.Ecto.Helpers.regex("elixir", "i")
from p in Post, where: fragment(title: ^regex)
The other one is to use the $regex operator:
from p in Post, where: fragment(title: ["$regex": "elixir", "$options": "i"])
For more information about the differences between the two syntaxes please refer to the MongoDB documentation: http://docs.mongodb.org/manual/reference/operator/query/regex/#syntax-restrictions
Options
i- case insensitivem- causes ^ and $ to mark the beginning and end of each linex- whitespace characters are ignored except when escaped and allow # to delimit comments, requires using$regexoperator together with the$optionoperators- causes dot to match newlines, requires using$regexoperator together with the$optionoperator
Summary
Functions
Casts to database format
Converts a Mongo.Ecto.Regex into BSON.Regex
Converts a BSON.Regex into Mongo.Ecto.Regex
The Ecto primitive type
Types
Functions
Converts a Mongo.Ecto.Regex into BSON.Regex
Converts a BSON.Regex into Mongo.Ecto.Regex