Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

{struct,Obj} for mochijson compatibility

  • Loading branch information...
1 parent 23b32bd commit 7d426e7327967ff487b76a70aece48b2267f6654 @SergejJurecko committed
Showing with 12 additions and 1 deletion.
  1. +9 −1 README.rdoc
  2. +3 −0  mongodb.erl
10 README.rdoc
@@ -15,13 +15,21 @@ For instance:
% This will NOT work
Mong:findOne(#mydoc{i = 10}, [#mydoc.i,]).
+WARNING: If you use modifier updates with {set,Value} ($set), do not use records. Mongo changes the document element sequence and this messes up record serialization.
Connections are always single:
- master/slave - read and write from master
- master/master - pick a master at random and use it for everything
- replica pairs - find out which is master and connect to it
If your usage pattern is read heavy and want to use slaves for reading, connect to them with singleServer call. Don't write to slave connections or bad things will happen.
-Always use an atom for naming connections. The connection process will register itself on that name.
+Always use an atom for naming connections. The connection process will register itself on that name.
+Runtime connection API:
Connection info is saved in an application variable (erlmongo,connections) and updated with every call to: singleServer, masterSlave, replicaPairs, masterMaster and deleteConnection. If mongodb process crashes for some reason, connections will be restarted. Also if the application itself is stopped and started. You can add a connections variable to file:
% def is name of connection, types can be: masterSlave,masterMaster or replicaPairs. This is how singleServer info is saved:
3  mongodb.erl
@@ -1093,6 +1093,9 @@ encode_element({Name, {bson, Bin}}) ->
<<3, Name/binary, 0, Bin/binary>>;
encode_element({Name, {binary, 2, Data}}) ->
<<5, Name/binary, 0, (byte_size(Data)+4):32/little-signed, 2:8, (byte_size(Data)):32/little-signed, Data/binary>>;
+encode_element({Name,{struct,Items}}) ->
+ Binary = encode(Items),
+ <<3, Name/binary, 0, Binary/binary>>;
encode_element({Name, {inc, Val}}) ->
encode_element({<<"$inc">>, [{Name, Val}]});
encode_element({Name, {set, Val}}) ->

0 comments on commit 7d426e7

Please sign in to comment.
Something went wrong with that request. Please try again.