Mongo.Ecto.Regex (mongodb_ecto v1.1.2) View Source
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$regex
operator together with the$option
operators
- causes dot to match newlines, requires using$regex
operator together with the$option
operator
Link to this section Summary
Functions
Casts to database format
Converts a Mongo.Ecto.Regex
into BSON.Regex
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
Converts a BSON.Regex
into Mongo.Ecto.Regex
The Ecto primitive type.
Link to this section Types
Specs
Link to this section Functions
Casts to database format
Converts a Mongo.Ecto.Regex
into BSON.Regex
Callback implementation for Ecto.Type.embed_as/1
.
Callback implementation for Ecto.Type.equal?/2
.
Converts a BSON.Regex
into Mongo.Ecto.Regex
The Ecto primitive type.