You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -105,6 +113,18 @@ For additional information on usage please see the documentation for [Ecto](http
105
113
| timestamp |`BSON.Timestamp`|
106
114
| 64-bit integer |`:integer`|
107
115
116
+
Primary keys on Ecto schemas are named `:id` and represented as strings, whereas in the actual MongoDB collection, they are named `_id` and stored as object ids. Schema definitions for MongoDB collections should start with `@primary_key {:id, :binary_id, autogenerate: true}` like in the above example. To create an `:id` for an Ecto struct, use `BSON.ObjectId.encode!(Mongo.object_id())`, e.g.:
117
+
118
+
```elixir
119
+
weather = %Weather{
120
+
id:BSON.ObjectId.encode!(Mongo.object_id()),
121
+
city:"New York City",
122
+
temp_lo:32,
123
+
temp_hi:50,
124
+
prcp:0.0
125
+
}
126
+
```
127
+
108
128
Symbols are deprecated by the
109
129
[BSON specification](http://bsonspec.org/spec.html). They will be converted
110
130
to simple strings on reads. There is no possibility of persisting them to
@@ -126,25 +146,28 @@ The adapter and the driver are tested against most recent versions from 5.0, 6.0
126
146
127
147
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`.
128
148
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:
149
+
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:
150
+
130
151
1.`Mongo` functions no longer accept a `pool` option or `MyApp.Repo.Pool` module argument. Instead, a pool PID is expected:
# Provided the following function is defined in MyApp.Repo:
162
+
defmoduleMyApp.Repodo
163
+
useEcto.Repo, otp_app::my_app, adapter:Mongo.Ecto
164
+
165
+
defpool() do
166
+
Ecto.Adapter.lookup_meta(__MODULE__).pid
167
+
end
168
+
end
169
+
```
170
+
148
171
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)`.
149
172
3.`Mongo.ReadPreferences.defaults` is renamed to `Mongo.ReadPreference.merge_defaults`.
150
173
4. When passing a `hint` to `Mongo.find_one` etc., if the hinted index does not exist, an error is now returned.
Copy file name to clipboardExpand all lines: lib/mongo_ecto.ex
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@ defmodule Mongo.Ecto do
28
28
password: "mongodb",
29
29
hostname: "localhost"
30
30
31
+
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: `.
32
+
31
33
Each repository in Ecto defines a `start_link/0` function that needs to be
32
34
invoked before using the repository. This function is generally from your
0 commit comments