{"id":13480690,"url":"https://github.com/elixir-mongo/mongodb_ecto","last_synced_at":"2025-05-14T12:10:06.210Z","repository":{"id":32661997,"uuid":"36249824","full_name":"elixir-mongo/mongodb_ecto","owner":"elixir-mongo","description":"MongoDB adapter for Ecto","archived":false,"fork":false,"pushed_at":"2025-03-12T20:08:58.000Z","size":602,"stargazers_count":377,"open_issues_count":22,"forks_count":127,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-05-13T19:02:47.754Z","etag":null,"topics":["ecto","elixir","mongodb"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"protobi/js-xlsx","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elixir-mongo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-05-25T19:18:02.000Z","updated_at":"2025-05-09T20:16:04.000Z","dependencies_parsed_at":"2022-07-20T13:48:00.990Z","dependency_job_id":"369e4fd2-c6d0-4364-93a1-c3aca3c908f3","html_url":"https://github.com/elixir-mongo/mongodb_ecto","commit_stats":{"total_commits":349,"total_committers":31,"mean_commits":"11.258064516129032","dds":0.5272206303724929,"last_synced_commit":"83587c2c5d14f5956ad78ffaba62630515e44e06"},"previous_names":["michalmuskala/mongodb_ecto","kobil-systems/mongodb_ecto"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-mongo%2Fmongodb_ecto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-mongo%2Fmongodb_ecto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-mongo%2Fmongodb_ecto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elixir-mongo%2Fmongodb_ecto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elixir-mongo","download_url":"https://codeload.github.com/elixir-mongo/mongodb_ecto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254140756,"owners_count":22021219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecto","elixir","mongodb"],"created_at":"2024-07-31T17:00:43.686Z","updated_at":"2025-05-14T12:10:06.166Z","avatar_url":"https://github.com/elixir-mongo.png","language":"Elixir","funding_links":[],"categories":["Libraries","Elixir"],"sub_categories":["Elixir"],"readme":"# Mongo.Ecto\n\n![CI](https://github.com/elixir-mongo/mongodb_ecto/actions/workflows/ci.yml/badge.svg)\n[![Hex.pm](https://img.shields.io/hexpm/v/mongodb_ecto.svg)](https://hex.pm/packages/mongodb_ecto)\n[![Module Version](https://img.shields.io/hexpm/v/mongodb_ecto.svg)](https://hex.pm/packages/mongodb_ecto)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/mongodb_ecto/)\n[![Total Download](https://img.shields.io/hexpm/dt/mongodb_ecto.svg)](https://hex.pm/packages/mongodb_ecto)\n[![License](https://img.shields.io/hexpm/l/mongodb_ecto.svg)](https://github.com/elixir-mongo/mongodb_ecto/blob/master/LICENSE)\n[![Last Updated](https://img.shields.io/github/last-commit/elixir-mongo/mongodb_ecto.svg)](https://github.com/elixir-mongo/mongodb_ecto/commits/master)\n\n`Mongo.Ecto` is a MongoDB adapter for Ecto.\n\nFor detailed information read the documentation for the `Mongo.Ecto` module,\nor check out examples below.\n\n## Example\n\n```elixir\n# In your config/config.exs file\nconfig :my_app, Repo,\n  adapter: Mongo.Ecto,\n  # Example key-value configuration:\n  database: \"ecto_simple\",\n  username: \"mongodb\",\n  password: \"mongodb\",\n  hostname: \"localhost\"\n  # OR you can configure with a connection string (mongodb:// or mongodb+srv://):\n  mongo_url: \"mongodb://mongodb:mongodb@localhost:27017/ecto_simple\"\n\nconfig :my_app,\n  # Add Repo to this list so you can run commands like `mix ecto.create`.\n  ecto_repos: [Repo]\n\n# In your application code\ndefmodule Repo do\n  use Ecto.Repo,\n    otp_app: :my_app,\n    adapter: Mongo.Ecto\n\n  def pool() do\n    Ecto.Adapter.lookup_meta(__MODULE__).pid\n  end\nend\n\ndefmodule Weather do\n  use Ecto.Schema\n\n  # see Mongo.Ecto module docs for explanation of this line\n  @primary_key {:id, :binary_id, autogenerate: true}\n\n  # weather is the MongoDB collection name\n  schema \"weather\" do\n    field :city     # Defaults to type :string\n    field :temp_lo, :integer\n    field :temp_hi, :integer\n    field :prcp,    :float, default: 0.0\n  end\nend\n\ndefmodule Simple do\n  import Ecto.Query\n\n  def sample_query do\n    query = from w in Weather,\n          where: w.prcp \u003e 0 or is_nil(w.prcp),\n         select: w\n    Repo.all(query)\n  end\nend\n```\n\n## Usage\n\nAdd `:mongodb_ecto` as a dependency in your `mix.exs` file.\n\n```elixir\ndef deps do\n  [\n    {:mongodb_ecto, \"~\u003e 2.1.1\"}\n  ]\nend\n```\n\nTo use the adapter in your repo:\n\n```elixir\ndefmodule MyApp.Repo do\n  use Ecto.Repo,\n    otp_app: :my_app,\n    adapter: Mongo.Ecto\nend\n```\n\nFor additional information on usage please see the documentation for the [Mongo.Ecto module](https://hexdocs.pm/mongodb_ecto/Mongo.Ecto.html) and for [Ecto](http://hexdocs.pm/ecto).\n\n## Data Type Mapping\n\n| BSON               | Ecto                    |\n| ------------------ | ----------------------- |\n| double             | `:float`                |\n| string             | `:string`               |\n| object             | `:map`                  |\n| array              | `{:array, subtype}`     |\n| binary data        | `:binary`               |\n| binary data (uuid) | `Ecto.UUID`             |\n| object id          | `:binary_id`            |\n| boolean            | `:boolean`              |\n| date               | `Ecto.DateTime`         |\n| regular expression | `Mongo.Ecto.Regex`      |\n| JavaScript         | `Mongo.Ecto.JavaScript` |\n| symbol             | (see below)             |\n| 32-bit integer     | `:integer`              |\n| timestamp          | `BSON.Timestamp`        |\n| 64-bit integer     | `:integer`              |\n\nSymbols are deprecated by the\n[BSON specification](http://bsonspec.org/spec.html). They will be converted\nto simple strings on reads. There is no possibility of persisting them to\nthe database.\n\nAdditionally special values are translated as follows:\n\n| BSON    | Ecto        |\n| ------- | ----------- |\n| null    | `nil`       |\n| min key | `:BSON_min` |\n| max key | `:BSON_max` |\n\n## Supported Mongo versions\n\nThe adapter and the driver are tested against most recent versions from 5.0, 6.0, and 7.0.\n\n## Migrating to 2.0\n\nRelease 2.0 changes the underlying driver from [`mongodb`](https://github.com/elixir-mongo/mongodb) to [`mongodb_driver`](https://github.com/zookzook/elixir-mongodb-driver) 1.4. Calls to the Ecto adapter itself should not require any changes. Some config options are no longer used and can be simply deleted: `pool`, `pool_overflow`, `pool_timeout`.\n\nIf you make direct calls to the `Mongo` driver, you will need to update some of them to account for the `mongodb` -\u003e `mongodb_driver` upgrade. Also, remember to replace `:mongodb` with `{:mongodb_driver, \"~\u003e 1.4\"}` in your `mix.exs`. The known updates are:\n\n1. `Mongo` functions no longer accept a `pool` option or `MyApp.Repo.Pool` module argument. Instead, a pool PID is expected:\n\n   ```elixir\n   # Old driver call\n   Mongo.find(MyApp.Repo.Pool, \"my_coll\", %{\"id\": id}, projection: %{\"field\": 1}, pool: db_pool())\n\n   # New driver call\n   Mongo.find(MyApp.Repo.pool(), \"my_coll\", %{\"id\": id}, projection: %{\"field\": 1})\n\n   # repo.ex\n   # Provided the following function is defined in MyApp.Repo:\n   defmodule MyApp.Repo do\n     use Ecto.Repo, otp_app: :my_app, adapter: Mongo.Ecto\n\n     def pool() do\n       Ecto.Adapter.lookup_meta(__MODULE__).pid\n     end\n   end\n   ```\n\n2. [`Mongo.command`](https://hexdocs.pm/mongodb_driver/1.4.1/Mongo.html#command/3) requires a keyword list instead of a document. E.g., instead of `Mongo.command(MyApp.Repo.pool(), %{listCollections: 1}, opts)`, do `Mongo.command(MyApp.Repo.pool(), [listCollections: 1], opts)`.\n3. `Mongo.ReadPreferences.defaults` is renamed to `Mongo.ReadPreference.merge_defaults`.\n4. When passing a `hint` to `Mongo.find_one` etc., if the hinted index does not exist, an error is now returned.\n\n## Contributing\n\nTo contribute you need to compile `Mongo.Ecto` from source and test it:\n\n```\n$ git clone https://github.com/ankhers/mongodb_ecto.git\n$ cd mongodb_ecto\n$ mix test\n```\n\n## Copyright and License\n\nCopyright 2015 Michał Muskała\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-mongo%2Fmongodb_ecto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felixir-mongo%2Fmongodb_ecto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felixir-mongo%2Fmongodb_ecto/lists"}