mongo v0.5.4 Mongo.Server
Manage the connection to a mongodb server
Summary
Functions
Returns true if connection mode is active
Assigns radom ids to a list of documents when :_id is missing
Closes the connection
Executes an admin command to the server
Sends a command message requesting imediate response
connects to local mongodb server by defaults to {"127.0.0.1", 27017}
connects to a mongodb server specifying options
connects to a mongodb server
Gets mongo connection default options
Adds options to an existing mongo server connection
Pings the server
Retreives a repsonce from the MongoDB server (only for passive mode)
Sends a message to MongoDB
Functions
Assigns radom ids to a list of documents when :_id is missing
iex> [%{a: 1}] |> Mongo.Server.assign_id |> Enum.at(0) |> Map.keys
[:"_id", :a]
#a prefix to ids can be set manually like this
iex> prefix = case [%{a: 1}] |> Mongo.Server.assign_id(256*256-1) |> Enum.at(0) |> Map.get(:"_id") do
...> %Bson.ObjectId{oid: <<prefix::16, _::binary>>} -> prefix
...> error -> error
...> end
...> prefix
256*256-1
#by default prefix are set at connection time and remains identical for the entire connection
iex> mongo = Mongo.connect!
...> prefix = case [%{a: 1}] |> Mongo.Server.assign_id(mongo) |> Enum.at(0) |> Map.get(:"_id") do
...> %Bson.ObjectId{oid: <<prefix::16, _::binary>>} -> prefix
...> error -> error
...> end
...> prefix == mongo.id_prefix
true
connects to local mongodb server by defaults to {"127.0.0.1", 27017}
This can be overwritten by the environment variable :host, ie:
[
{mongo,
[
{host, {"127.0.0.1", 27017}}
]}
].
Adds options to an existing mongo server connection
new_opts must be a map with zero or more of the following keys:
- read:
:awaitdata,:nocursortimeout,:slaveok,:tailablecursor - write concern:
:wc - socket:
:mode,:timeout
Retreives a repsonce from the MongoDB server (only for passive mode)