Skip to content

Commit 77a9d28

Browse files
author
Justin Wood
committed
Add support for the :mongo_url key
1 parent d10c29b commit 77a9d28

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/mongo_ecto.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,13 @@ defmodule Mongo.Ecto do
336336
* `:port` - Server port (default: `27017`)
337337
* `:username` - Username
338338
* `:password` - User password
339-
* `:connect_timeout` - The timeout for establishing new connections (default: 5000)
339+
* `:mongo_url` - A MongoDB [URL](https://docs.mongodb.com/manual/reference/connection-string/)
340+
* `:connect_timeout` - The timeout for establishing new connections
341+
(default: 5000)
340342
* `:w` - MongoDB's write convern (default: 1). If set to 0, some of the
341343
Ecto's functions may not work properely
342-
* `:j`, `:fsync`, `:wtimeout` - Other MongoDB's write concern options. Please
343-
consult MongoDB's documentation
344+
* `:j`, `:fsync`, `:wtimeout` - Other MongoDB's write concern options.
345+
Please consult MongoDB's documentation
344346
345347
### Pool options
346348
@@ -417,6 +419,12 @@ defmodule Mongo.Ecto do
417419
repo.__pool__
418420
end
419421

422+
# Rename the `:mongo_url` key so that the driver can parse it
423+
opts = Enum.map(opts, fn
424+
{:mongo_url, value} -> {:url, value}
425+
{key, value} -> {key, value}
426+
end)
427+
420428
opts = [name: pool_name] ++ Keyword.delete(opts, :pool) ++ pool_opts
421429

422430
Mongo.child_spec(opts)

0 commit comments

Comments
 (0)