Mongo.Ecto.Helpers (mongodb_ecto v1.1.2) View Source

Defines helpers to ease working with MongoDB in models or other places where you work with them. You'd probably want to import it.

Link to this section Summary

Functions

Allows updating only a fragment of a nested document inside an array

Allows updating only a fragment of a nested document

Creates proper regex object that can be passed to the database.

Link to this section Functions

Link to this function

change_array(idx, field \\ "", value)

View Source

Specs

change_array(pos_integer(), String.t(), term()) :: Mongo.Ecto.ChangeArray.t()

Allows updating only a fragment of a nested document inside an array

Usage in queries

MyRepo.update_all(Post,
  set: [comments: change_array(0, "author", "NewName")])
Link to this function

change_map(field, value)

View Source

Specs

change_map(String.t(), term()) :: Mongo.Ecto.ChangeMap.t()

Allows updating only a fragment of a nested document

Usage in queries

MyRepo.update_all(Post,
  set: [meta: change_map("author.name", "NewName")])
Link to this function

regex(pattern, options \\ "")

View Source

Specs

Creates proper regex object that can be passed to the database.

Usage in queries

from p in Post,
  where: fragment(title: ^regex("elixir", "i"))

For supported options please see Mongo.Ecto.Regex module documentation.