anchor.diff:  -export([start/0, start/1, stop/1, find/2, find/7]).
   -export([count/3, counter/2, incr/3, delete/2, save_record/2]).
   -export([push/2, pop/2, dump/1, execute/2]).
  --define(GREGORIAN_SECONDS_1970, 62167219200). % http://stackoverflow.com/questions/3672287/date-to-megaseconds
  --define(LOG(Name, Value), io:format("@@@ ~s: ~p~n", [Name, Value])).
  +
  +-define(LOG(Name, Value), io:format("DEBUG: ~s: ~p~n", [Name, Value])).
  +
  +% Number of seconds between beginning of gregorian calendar and 1970
  +-define(GREGORIAN_SECONDS_1970, 62167219200). 
  +
  +% JavaScript expression formats to query MongoDB
  +-define(CONTAINS_FORMAT, "this.~s.indexOf('~s') != -1").
  +-define(NOT_CONTAINS_FORMAT, "this.~s.indexOf('~s') == -1").
  +
   
   start() ->
       start([]).
  
positive.code:         {connection_failure, Reason} -> {error, Reason}
      end.
  
  push(Conn, Depth) ->
      ok.
  
  pop(Conn, Depth) ->
      ok.
  
  dump(_Conn) -> "".
  
  %execute(Conn, Commands) ->
  %    pgsql:squery(Conn, Commands).
  
  % internal
  
  infer_type_from_id(Id) when is_list(Id) ->
      [Type, BossId] = string:tokens(Id, "-"),
      {list_to_atom(Type), type_to_collection(Type), boss_to_mongo_id(Id)}.
  
  type_to_table_name(Type) when is_atom(Type) ->
      type_to_table_name(atom_to_list(Type));
  type_to_table_name(Type) when is_list(Type) ->
      inflector:pluralize(Type).
  
  activate_record(Record, Metadata, Type) ->
      DummyRecord = apply(Type, new, lists:seq(1, proplists:get_value(new, Type:module_info(exports)))),
      apply(Type, new, lists:map(fun
                  (id) ->
                      Index = keyindex(<<"id">>, 2, Metadata),
                      atom_to_list(Type) ++ "-" ++ integer_to_list(element(Index, Record));
                  (Key) ->
                      Index = keyindex(list_to_binary(atom_to_list(Key)), 2, Metadata),
                      case element(Index, Record) of
                          {Date, {_, _, S} = Time} when is_float(S) ->
                              {Date, setelement(3, Time, round(S))};
                          Val -> Val
                      end
              end, DummyRecord:attribute_names())).
  
  model_is_loaded(Type) ->
      case code:is_loaded(Type) of
  
negative.code:         {failure, Reason} -> {error, Reason};
          {connection_failure, Reason} -> {error, Reason}
      end.
  
  find(Conn, Type, Conditions, Max, Skip, Sort, SortOrder) when is_atom(Type), is_list(Conditions), 
                                                                is_integer(Max), is_integer(Skip), 
  