Skip to content

Commit e2f0bbe

Browse files
committed
autogenerate: refer to module docs instead
1 parent c429f71 commit e2f0bbe

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

README.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ end
4040
defmodule Weather do
4141
use Ecto.Schema
4242

43+
# see Mongo.Ecto module docs for explanation of this line
4344
@primary_key {:id, :binary_id, autogenerate: true}
45+
46+
# weather is the MongoDB collection name
4447
schema "weather" do
4548
field :city # Defaults to type :string
4649
field :temp_lo, :integer
@@ -105,18 +108,6 @@ For additional information on usage please see the documentation for [Ecto](http
105108
| timestamp | `BSON.Timestamp` |
106109
| 64-bit integer | `:integer` |
107110

108-
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.:
109-
110-
```elixir
111-
weather = %Weather{
112-
id: BSON.ObjectId.encode!(Mongo.object_id()),
113-
city: "New York City",
114-
temp_lo: 32,
115-
temp_hi: 50,
116-
prcp: 0.0
117-
}
118-
```
119-
120111
Symbols are deprecated by the
121112
[BSON specification](http://bsonspec.org/spec.html). They will be converted
122113
to simple strings on reads. There is no possibility of persisting them to

lib/mongo_ecto.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule Mongo.Ecto do
5252
defmodule Weather do
5353
use Ecto.Model
5454
55-
# see the note below for explanation of that line
55+
# see the note below for explanation of this line
5656
@primary_key {:id, :binary_id, autogenerate: true}
5757
5858
# weather is the MongoDB collection name

0 commit comments

Comments
 (0)