anchor.diff:    RMode = mc_utils:get_value(r_mode, Options, master),
     WMode = mc_utils:get_value(w_mode, Options, unsafe),
     #conn_state{database = Database, read_mode = RMode, write_mode = WMode}.
  +
  +
   
   %% @private
   %% Register this process if needed
  
positive.code:   handle_cast/2,
    handle_info/2,
    terminate/2,
    code_change/3
  ]).
  
  -record(state, {
    socket :: gen_tcp:socket(),
  
negative.code: disconnect(Worker) ->
    gen_server:cast(Worker, halt).
  
  
  init(Options) ->
    Proxy = proplists:get_value( proxy, Options, false ),
    init_local( Proxy, Options ).
  
  init_local( false, Options ) ->
    {ok, Socket} = mc_auth:connect_to_database(Options),
    ConnState = form_state(Options),
    try_register(Options),
    proc_lib:init_ack({ok, self()}),
    mc_auth:auth(Socket, Options, ConnState#conn_state.database),
    gen_server:enter_loop(?MODULE, [], #state{socket = Socket, conn_state = ConnState});
  
  init_local( true, Options ) ->
    {ok, Socket} = mc_auth:connect_to_database(Options),
    ConnState = form_state(Options),
    try_register(Options),
    mc_auth:auth(Socket, Options, ConnState#conn_state.database),
    {ok, #state{socket = Socket, conn_state = ConnState} }.
  
  
  
  handle_call(NewState = #conn_state{}, _, State = #state{conn_state = OldState}) ->  % update state, return old
    {reply, {ok, OldState}, State#state{conn_state = NewState}};
  
  handle_call(#ensure_index{collection = Coll, index_spec = IndexSpec}, _, State = #state{conn_state = ConnState, socket = Socket}) % ensure index request with insert request
    ->
  
    Key = maps:get(<<"key">>, IndexSpec),
    Defaults = {<<"name">>, mc_worker_logic:gen_index_name(Key), <<"unique">>, false, <<"dropDups">>, false},
    Index = bson:update(<<"ns">>, mongo_protocol:dbcoll(ConnState#conn_state.database, Coll), bson:merge(IndexSpec, Defaults)),
    {ok, _} = mc_worker_logic:make_request(Socket, ConnState#conn_state.database,
      #insert{collection = <<"system.indexes">>, documents = [Index]}),
    {reply, ok, State};
  
  
  
  handle_call(Request, From, State = #state{socket = Socket, conn_state = ConnState = #conn_state{}, request_storage = ReqStor})
    when is_record(Request, insert); is_record(Request, update); is_record(Request, delete) % write requests
    ->
  
    case ConnState#conn_state.write_mode of
      unsafe ->   %unsafe (just write)
        {ok, _} = mc_worker_logic:make_request(Socket, ConnState#conn_state.database, Request),
  