Skip to content

Commit 6c91c0e

Browse files
committed
Merge branch 'master' of https://github.com/elixir-mongo/mongodb_ecto into mweidner/release-2_1_0
2 parents 8fa7ecf + b11e433 commit 6c91c0e

File tree

3 files changed

+85
-62
lines changed

3 files changed

+85
-62
lines changed

CHANGELOG.md

+36-30
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,74 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
## 2.0.0
1313

14-
* Change underlying driver from [`mongodb`](https://github.com/elixir-mongo/mongodb) to [`mongodb_driver`](https://github.com/zookzook/elixir-mongodb-driver) 1.4.0
15-
* Remove config options `pool`, `pool_overflow`, and `pool_timeout`
16-
* Add support for MongoDB 6.0 and 7.0
17-
* Add support for loading & dumping nil binaries and dumping nil dates
14+
- Change underlying driver from [`mongodb`](https://github.com/elixir-mongo/mongodb) to [`mongodb_driver`](https://github.com/zookzook/elixir-mongodb-driver) 1.4
15+
- Remove config options `pool`, `pool_overflow`, and `pool_timeout`
16+
- Add support for MongoDB 6.0 and 7.0
17+
- Add support for loading & dumping nil binaries and dumping nil dates
18+
- Improve README setup instructions
1819

1920
### Possible breaking changes
2021

2122
Calls to the Ecto adapter itself should not require any changes. However, if you make direct calls to the `Mongo` driver, you will need to update some of them to account for the `mongodb` -> `mongodb_driver` upgrade. See [Migrating to 2.0](./README.md#migrating-to-20) in the Readme.
2223

2324
## 1.1.2
24-
* Add support for loading nil dates
25+
26+
- Add support for loading nil dates
2527

2628
## 1.1.1
27-
* Allow `binary_id` fields to be nil
29+
30+
- Allow `binary_id` fields to be nil
2831

2932
## 1.1.0
30-
* Add support for Ecto 1.11
33+
34+
- Add support for Ecto 1.11
3135

3236
## 1.0.0
3337

34-
* Introduce support for Ecto 3
35-
* Introduce GitHub actions, replacing Travis CI
36-
* Use MongoDB 1.0.0 to add support for Mongodb 4.4. and 5.0
38+
- Introduce support for Ecto 3
39+
- Introduce GitHub actions, replacing Travis CI
40+
- Use MongoDB 1.0.0 to add support for Mongodb 4.4. and 5.0
3741

38-
* NOTE: This might work with versions of Ecto less than 3.6.
39-
Refer to the ecto-3 branch if you need to find a commit that works with a non-officially supported version
40-
of Ecto.
42+
- NOTE: This might work with versions of Ecto less than 3.6.
43+
Refer to the ecto-3 branch if you need to find a commit that works with a non-officially supported version
44+
of Ecto.
4145

4246
### Possible breaking changes
4347

44-
* Some upsert operations are only supported with MongoDBs 4.2 or newer.
48+
- Some upsert operations are only supported with MongoDBs 4.2 or newer.
4549

4650
## v0.1.4 (2016-03-03)
4751

48-
* Support MongoDB version 3.2
52+
- Support MongoDB version 3.2
4953

5054
## v0.1.3 (2016-01-15)
5155

52-
* This version is limited to Ecto 1.0 because of known issues with 1.1
56+
- This version is limited to Ecto 1.0 because of known issues with 1.1
5357

54-
* Additions:
55-
* Implement `count(field, :distinct)`
58+
- Additions:
5659

57-
* Bug fixes:
58-
* Handle models without autogenerated primary key on update and delete
59-
* Implement `Ecto.Adapter.stop/2` callback
60-
* Move encoding to adapter `load` and `dump` callbacks
60+
- Implement `count(field, :distinct)`
61+
62+
- Bug fixes:
63+
- Handle models without autogenerated primary key on update and delete
64+
- Implement `Ecto.Adapter.stop/2` callback
65+
- Move encoding to adapter `load` and `dump` callbacks
6166

6267
## v0.1.2 (2015-10-18)
6368

64-
* Breaking changes:
65-
* Raise on `limit` and `offset` in `update_all` and `delete_all` queries,
66-
it's not supported by MongoDB, we were failing siletnly before
69+
- Breaking changes:
70+
71+
- Raise on `limit` and `offset` in `update_all` and `delete_all` queries,
72+
it's not supported by MongoDB, we were failing siletnly before
6773

68-
* Bug fixes:
69-
* Allow interpolation in limit and offset
74+
- Bug fixes:
75+
- Allow interpolation in limit and offset
7076

7177
## v0.1.1 (2015-08-30)
7278

73-
* Bug fixes:
74-
* Fix logging issues on find queries
79+
- Bug fixes:
80+
- Fix logging issues on find queries
7581

7682
## v0.1.0 (2015-08-25)
7783

78-
* First release
84+
- First release

README.md

+42-31
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,36 @@ or check out examples below.
1919
# In your config/config.exs file
2020
config :my_app, Repo,
2121
adapter: Mongo.Ecto,
22+
# Example key-value configuration:
2223
database: "ecto_simple",
2324
username: "mongodb",
24-
password: "mongosb",
25+
password: "mongodb",
2526
hostname: "localhost"
27+
# OR you can configure with a connection string (mongodb:// or mongodb+srv://):
28+
mongo_url: "mongodb://mongodb:mongodb@localhost:27017/ecto_simple"
29+
30+
config :my_app,
31+
# Add Repo to this list so you can run commands like `mix ecto.create`.
32+
ecto_repos: [Repo]
2633

2734
# In your application code
2835
defmodule Repo do
29-
use Ecto.Repo, otp_app: :my_app
36+
use Ecto.Repo,
37+
otp_app: :my_app,
38+
adapter: Mongo.Ecto
39+
40+
def pool() do
41+
Ecto.Adapter.lookup_meta(__MODULE__).pid
42+
end
3043
end
3144

3245
defmodule Weather do
33-
use Ecto.Model
46+
use Ecto.Schema
3447

48+
# see Mongo.Ecto module docs for explanation of this line
3549
@primary_key {:id, :binary_id, autogenerate: true}
50+
51+
# weather is the MongoDB collection name
3652
schema "weather" do
3753
field :city # Defaults to type :string
3854
field :temp_lo, :integer
@@ -65,14 +81,6 @@ def deps do
6581
end
6682
```
6783

68-
You should also update your applications to include both projects:
69-
70-
```elixir
71-
def application do
72-
[applications: [:logger, :mongodb_ecto, :ecto]]
73-
end
74-
```
75-
7684
To use the adapter in your repo:
7785

7886
```elixir
@@ -83,7 +91,7 @@ defmodule MyApp.Repo do
8391
end
8492
```
8593

86-
For additional information on usage please see the documentation for [Ecto](http://hexdocs.pm/ecto).
94+
For 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).
8795

8896
## Data Type Mapping
8997

@@ -124,27 +132,30 @@ The adapter and the driver are tested against most recent versions from 5.0, 6.0
124132

125133
## Migrating to 2.0
126134

127-
Release 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.0. 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`.
135+
Release 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`.
136+
137+
If you make direct calls to the `Mongo` driver, you will need to update some of them to account for the `mongodb` -> `mongodb_driver` upgrade. Also, remember to replace `:mongodb` with `{:mongodb_driver, "~> 1.4"}` in your `mix.exs`. The known updates are:
128138

129-
If you make direct calls to the `Mongo` driver, you will need to update some of them to account for the `mongodb` -> `mongodb_driver` upgrade. Also, remember to replace `:mongodb` with `{:mongodb_driver, "~> 1.4.0"}` in your `mix.exs`. The known updates are:
130139
1. `Mongo` functions no longer accept a `pool` option or `MyApp.Repo.Pool` module argument. Instead, a pool PID is expected:
131-
```elixir
132-
# Old driver call
133-
Mongo.find(MyApp.Repo.Pool, "my_coll", %{"id": id}, projection: %{"field": 1}, pool: db_pool())
134-
135-
# New driver call
136-
Mongo.find(MyApp.Repo.pool(), "my_coll", %{"id": id}, projection: %{"field": 1})
137-
138-
# repo.ex
139-
# Provided the following function is defined in MyApp.Repo:
140-
defmodule MyApp.Repo do
141-
use Ecto.Repo, otp_app: :my_app, adapter: Mongo.Ecto
142-
143-
def pool() do
144-
Ecto.Adapter.lookup_meta(__MODULE__).pid
145-
end
146-
end
147-
```
140+
141+
```elixir
142+
# Old driver call
143+
Mongo.find(MyApp.Repo.Pool, "my_coll", %{"id": id}, projection: %{"field": 1}, pool: db_pool())
144+
145+
# New driver call
146+
Mongo.find(MyApp.Repo.pool(), "my_coll", %{"id": id}, projection: %{"field": 1})
147+
148+
# repo.ex
149+
# Provided the following function is defined in MyApp.Repo:
150+
defmodule MyApp.Repo do
151+
use Ecto.Repo, otp_app: :my_app, adapter: Mongo.Ecto
152+
153+
def pool() do
154+
Ecto.Adapter.lookup_meta(__MODULE__).pid
155+
end
156+
end
157+
```
158+
148159
2. [`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)`.
149160
3. `Mongo.ReadPreferences.defaults` is renamed to `Mongo.ReadPreference.merge_defaults`.
150161
4. When passing a `hint` to `Mongo.find_one` etc., if the hinted index does not exist, an error is now returned.

lib/mongo_ecto.ex

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ defmodule Mongo.Ecto do
2828
password: "mongodb",
2929
hostname: "localhost"
3030
31+
config :my_app,
32+
# Add Repo to this list so you can run commands like `mix ecto.create`.
33+
ecto_repos: [Repo]
34+
35+
For more connection options, see mongodb-driver's [Mongo.start_link](https://hexdocs.pm/mongodb_driver/1.5.2/Mongo.html#start_link/1). Note that to use a connection string (mongodb:// or mongodb+srv://), you must set `mongo_url: ` instead of `url: `.
36+
3137
Each repository in Ecto defines a `start_link/0` function that needs to be
3238
invoked before using the repository. This function is generally from your
3339
supervision tree:
@@ -50,7 +56,7 @@ defmodule Mongo.Ecto do
5056
defmodule Weather do
5157
use Ecto.Model
5258
53-
# see the note below for explanation of that line
59+
# see the note below for explanation of this line
5460
@primary_key {:id, :binary_id, autogenerate: true}
5561
5662
# weather is the MongoDB collection name

0 commit comments

Comments
 (0)