Skip to content

Commit dfd21c5

Browse files
Switch underlying driver to mongodb_driver for MongoDB 6.0+ support (#190)
* Upgrade docker-compose mongo image to 6.0.6 * Switch underlying driver to mongodb_driver for MongoDB 6.0+ support * Interpret matched_count != 1 as staleness error in Connection.update_one/3 Basing staleness on the modified_count is incorrect, since updates that match a document but leave it as-is is a successful no-op. The action should only be considered stale if the update query did not match any documents. * Use appropriate Hex release of mongodb_driver * CI: same Mongo versions as elixir-mongodb-driver * CI: don't restore old deps cache * remove unused deps * update mongo versions in readme --------- Co-authored-by: Matthew Weidner <[email protected]>
1 parent 6793f9b commit dfd21c5

File tree

10 files changed

+102
-112
lines changed

10 files changed

+102
-112
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ on:
33
- pull_request
44

55
jobs:
6-
76
codeQuality:
87
name: "Tests & Code Quality"
98
runs-on: ubuntu-20.04
109
strategy:
1110
fail-fast: false
1211
matrix:
13-
otpElixir: [
14-
{otp: "24.3.4.10", elixir: "1.14.3"}
15-
]
12+
otpElixir: [{ otp: "24.3.4.10", elixir: "1.14.3" }]
1613
steps:
1714
- name: repo checkout
1815
uses: actions/checkout@v2
@@ -27,7 +24,7 @@ jobs:
2724
_build
2825
key: ${{ runner.os }}-${{matrix.otpElixir.otp}}-${{matrix.otpElixir.elixir}}-mix-${{ hashFiles('**/mix.lock') }}
2926
restore-keys: |
30-
${{ runner.os }}-${{matrix.otpElixir.otp}}-${{matrix.otpElixir.elixir}}-mix-
27+
${{ runner.os }}-${{matrix.otpElixir.otp}}-${{matrix.otpElixir.elixir}}-mix-${{ hashFiles('**/mix.lock') }}
3128
- run: mix deps.get
3229
- run: mix credo --strict
3330
continue-on-error: true
@@ -39,12 +36,13 @@ jobs:
3936
strategy:
4037
fail-fast: false
4138
matrix:
42-
mongodb: ["4.4", "5.0"]
43-
otpElixir: [
44-
{otp: "22.3.4.26", elixir: "1.12.3"},
45-
{otp: "23.3.4.18", elixir: "1.13.4"},
46-
{otp: "24.3.4.10", elixir: "1.14.3"}
47-
]
39+
mongodb: ["5.0", "6.0", "7.0"]
40+
otpElixir:
41+
[
42+
{ otp: "22.3.4.26", elixir: "1.12.3" },
43+
{ otp: "23.3.4.18", elixir: "1.13.4" },
44+
{ otp: "24.3.4.10", elixir: "1.14.3" },
45+
]
4846
topology: [replica_set, server]
4947
steps:
5048
- name: repo checkout
@@ -66,7 +64,7 @@ jobs:
6664
_build
6765
key: ${{ runner.os }}-${{matrix.otpElixir.otp}}-${{matrix.otpElixir.elixir}}-mix-${{ hashFiles('**/mix.lock') }}
6866
restore-keys: |
69-
${{ runner.os }}-${{matrix.otpElixir.otp}}-${{matrix.otpElixir.elixir}}-mix-
67+
${{ runner.os }}-${{matrix.otpElixir.otp}}-${{matrix.otpElixir.elixir}}-mix-${{ hashFiles('**/mix.lock') }}
7068
- run: mix deps.get
7169
- run: mix test
7270
env:

README.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
[![License](https://img.shields.io/hexpm/l/mongodb_ecto.svg)](https://github.com/elixir-mongo/mongodb_ecto/blob/master/LICENSE)
99
[![Last Updated](https://img.shields.io/github/last-commit/elixir-mongo/mongodb_ecto.svg)](https://github.com/elixir-mongo/mongodb_ecto/commits/master)
1010

11-
1211
`Mongo.Ecto` is a MongoDB adapter for Ecto.
1312

1413
For detailed information read the documentation for the `Mongo.Ecto` module,
1514
or check out examples below.
1615

1716
## Example
17+
1818
```elixir
1919
# In your config/config.exs file
2020
config :my_app, Repo,
@@ -87,23 +87,23 @@ For additional information on usage please see the documentation for [Ecto](http
8787

8888
## Data Type Mapping
8989

90-
| BSON |Ecto|
91-
| ---------- |------|
92-
| double |`:float`|
93-
| string  |`:string`|
94-
| object |`:map`|
95-
| array |`{:array, subtype}`|
96-
| binary data |`:binary`|
97-
| binary data (uuid) |`Ecto.UUID`|
98-
| object id |`:binary_id`|
99-
| boolean |`:boolean`|
100-
| date |`Ecto.DateTime`|
101-
| regular expression |`Mongo.Ecto.Regex`|
102-
| JavaScript |`Mongo.Ecto.JavaScript`|
103-
| symbol |(see below)|
104-
| 32-bit integer |`:integer`|
105-
| timestamp |`BSON.Timestamp`|
106-
| 64-bit integer |`:integer`|
90+
| BSON | Ecto |
91+
| ------------------ | ----------------------- |
92+
| double | `:float` |
93+
| string  | `:string` |
94+
| object | `:map` |
95+
| array | `{:array, subtype}` |
96+
| binary data | `:binary` |
97+
| binary data (uuid) | `Ecto.UUID` |
98+
| object id | `:binary_id` |
99+
| boolean | `:boolean` |
100+
| date | `Ecto.DateTime` |
101+
| regular expression | `Mongo.Ecto.Regex` |
102+
| JavaScript | `Mongo.Ecto.JavaScript` |
103+
| symbol | (see below) |
104+
| 32-bit integer | `:integer` |
105+
| timestamp | `BSON.Timestamp` |
106+
| 64-bit integer | `:integer` |
107107

108108
Symbols are deprecated by the
109109
[BSON specification](http://bsonspec.org/spec.html). They will be converted
@@ -112,17 +112,15 @@ the database.
112112

113113
Additionally special values are translated as follows:
114114

115-
| BSON | Ecto|
116-
| ---------- | ------|
117-
| null | `nil`|
118-
| min key | `:BSON_min`|
119-
| max key | `:BSON_max`|
120-
115+
| BSON | Ecto |
116+
| ------- | ----------- |
117+
| null | `nil` |
118+
| min key | `:BSON_min` |
119+
| max key | `:BSON_max` |
121120

122121
## Supported Mongo versions
123122

124-
The adapter and the driver are tested against most recent versions from 2
125-
branches: 4.4 and 5.0
123+
The adapter and the driver are tested against most recent versions from 5.0, 6.0, and 7.0.
126124

127125
## Contributing
128126

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
version: "3.9"
33
services:
44
mongo:
5-
image: mongo:4.4.4
5+
image: mongo:6.0.6
66
ports:
77
- 27017:27017

lib/mongo_ecto.ex

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -397,24 +397,6 @@ defmodule Mongo.Ecto do
397397
defmacro __before_compile__(_env) do
398398
end
399399

400-
@pool_timeout 5_000
401-
@timeout 15_000
402-
403-
defp normalize_config(config) do
404-
config
405-
|> Keyword.delete(:name)
406-
|> Keyword.put_new(:timeout, @timeout)
407-
|> Keyword.put_new(:pool_timeout, @pool_timeout)
408-
end
409-
410-
defp pool_name(config) do
411-
Keyword.get(config, :pool_name, default_pool_name(config))
412-
end
413-
414-
defp default_pool_name(config) do
415-
Module.concat(Keyword.get(config, :name, config[:repo]), Pool)
416-
end
417-
418400
@doc false
419401
def application, do: :mongodb_ecto
420402

@@ -426,7 +408,7 @@ defmodule Mongo.Ecto do
426408
connection = Connection
427409

428410
unless Code.ensure_loaded?(connection) do
429-
driver = :mongodb
411+
driver = :mongodb_driver
430412

431413
raise """
432414
Could not find #{inspect(connection)}.
@@ -439,21 +421,18 @@ defmodule Mongo.Ecto do
439421
"""
440422
end
441423

442-
pool_name = pool_name(config)
443-
norm_config = normalize_config(config)
444-
445424
log = Keyword.get(config, :log, :debug)
446425
telemetry_prefix = Keyword.fetch!(config, :telemetry_prefix)
447426
telemetry = {config[:repo], log, telemetry_prefix ++ [:query]}
448427

449428
opts = Keyword.take(config, @pool_opts)
450-
meta = %{telemetry: telemetry, opts: opts, pool: {pool_name, norm_config}}
429+
meta = %{telemetry: telemetry, opts: opts}
451430
{:ok, connection.child_spec(config), meta}
452431
end
453432

454433
@impl true
455434
def ensure_all_started(_repo, type) do
456-
{:ok, _mongo} = Application.ensure_all_started(:mongodb, type)
435+
{:ok, _mongo} = Application.ensure_all_started(:mongodb_driver, type)
457436
end
458437

459438
@impl true
@@ -533,7 +512,12 @@ defmodule Mongo.Ecto do
533512
end
534513

535514
defp dump_date(%Date{} = date) do
536-
{:ok, date}
515+
dt =
516+
{Date.to_erl(date), {0, 0, 0}}
517+
|> NaiveDateTime.from_erl!()
518+
|> DateTime.from_naive!("Etc/UTC")
519+
520+
{:ok, dt}
537521
end
538522

539523
defp dump_date(nil), do: {:ok, nil}
@@ -806,7 +790,7 @@ defmodule Mongo.Ecto do
806790
if major_version > 3 || (major_version == 3 && minor_version >= 4) do
807791
_all_collection_names =
808792
repo
809-
|> command(%{listCollections: 1}, opts)
793+
|> command([listCollections: 1], opts)
810794
|> get_in(["cursor", "firstBatch"])
811795
# exclude mongo views which were introduced in version 3.4
812796
|> Enum.filter(&(&1["type"] == "collection"))
@@ -852,7 +836,7 @@ defmodule Mongo.Ecto do
852836
end
853837

854838
defp list_collections([major_version | _], repo, opts) when major_version >= 3 do
855-
colls = command(repo, %{listCollections: 1}, opts)["cursor"]["firstBatch"]
839+
colls = command(repo, [listCollections: 1], opts)["cursor"]["firstBatch"]
856840

857841
_all_collections =
858842
colls
@@ -880,7 +864,7 @@ defmodule Mongo.Ecto do
880864
end
881865

882866
defp db_version(repo) do
883-
command(repo, %{buildinfo: 1}, [])["versionArray"]
867+
command(repo, [buildinfo: 1], [])["versionArray"]
884868
end
885869

886870
@doc """

0 commit comments

Comments
 (0)