anchor.diff:          {failure, Reason} -> {error, Reason};
           {connection_failure, Reason} -> {error, Reason}
       end.
  +
  +boss_to_mongo_op(BossOperator) ->
  +    OperatorsMap = [
  +        {'not_equals', '$ne'},
  +        {'gt', '$gt'},
  +        {'ge', '$gte'},
  +        {'lt', '$lt'},
  +        {'le', '$lte'},
  +        {'in', '$in'},
  +        {'not_in', '$nin'}
  +    ],
  +    proplists:get_value(BossOperator, OperatorsMap).
  +
  +where_clause(Format, Params) ->
  +    erlang:iolist_to_binary(
  +                io_lib:format(Format, Params)).
  +
  +multiple_where_clauses_string(Format, Key, ValueList, Operator) ->
  +    ClauseList = lists:map(fun(Value) ->
  +                lists:flatten(io_lib:format(Format, [Key, Value]))
  +        end, ValueList),
  +        string:join(ClauseList, " " ++ Operator ++ " ").
  +
  +multiple_where_clauses(Format, Key, ValueList, Operator) ->
  +    erlang:iolist_to_binary(multiple_where_clauses_string(Format, Key,
  +            ValueList, Operator)).
  +
  +-define(CONTAINS_FORMAT, "this.~s.indexOf('~s') != -1").
  +-define(NOT_CONTAINS_FORMAT, "this.~s.indexOf('~s') == -1").
  +
  +build_conditions(Conditions) ->
  +    proplist_to_tuple(build_conditions1(Conditions, [])).
  +
  +build_conditions1([], Acc) ->
  +    Acc;
  +
  +build_conditions1([{Key, Operator, Value}|Rest], Acc) ->
  +%    ?LOG("Key, Operator, Value", {Key, Operator, Value}),
  +
  +    Condition = case {Operator, Value} of 
  +        {'not_matches', Value} ->
  +            [{Key, {'$not', {regex, list_to_binary(Value), <<"">>}}}];
  +        {'matches', Value} ->
  +            [{Key, {regex, list_to_binary(Value), <<"">>}}];
  +        {'contains', Value} ->
  +            WhereClause = where_clause(
  +                ?CONTAINS_FORMAT, [Key, Value]),
  +            [{'$where', WhereClause}];
  +        {'not_contains', Value} ->
  +            WhereClause = where_clause(
  +                ?NOT_CONTAINS_FORMAT, [Key, Value]),
  +            [{'$where', WhereClause}];
  +        {'contains_all', ValueList} ->
  +            WhereClause = multiple_where_clauses(
  +                ?CONTAINS_FORMAT, Key, ValueList, "&&"),
  +            [{'$where', WhereClause}];
  +        {'not_contains_all', ValueList} ->
  +            WhereClause = "!(" ++ multiple_where_clauses_string(
  +                ?CONTAINS_FORMAT, Key, ValueList, "&&") ++ ")",
  +            [{'$where', erlang:iolist_to_binary(WhereClause)}];
  +        {'contains_any', ValueList} ->
  +            WhereClause = multiple_where_clauses(
  +                ?CONTAINS_FORMAT, Key, ValueList, "||"),
  +            [{'$where', WhereClause}];
  +        {'contains_none', ValueList} ->
  +            WhereClause = multiple_where_clauses(
  +                ?NOT_CONTAINS_FORMAT, Key, ValueList, "&&"),
  +            [{'$where', WhereClause}];
  +        {'equals', Value} when is_list(Value) -> 
  +            [{Key, list_to_binary(Value)}];
  +        {'not_equals', Value} when is_list(Value) -> 
  +            [{Key, {'$ne', list_to_binary(Value)}}];
  +        {'equals', {{_,_,_},{_,_,_}} = Value} -> 
  +            [{Key, datetime_to_now(Value)}];
  +        {'equals', Value} -> 
  +            [{Key, Value}];
  +        {Operator, {{_,_,_},{_,_,_}} = Value} -> 
  +            [{Key, {boss_to_mongo_op(Operator), datetime_to_now(Value)}}];
  +        {'in', {Min, Max}} -> 
  +            [{Key, {'$gte', Min}}, {Key, {'$lte', Max}}];
  +        {'not_in', {Min, Max}} -> 
  +            [{'$or', [{Key, {'$lt', Min}}, {Key, {'$gt', Max}}]}];
  +        {Operator, Value} -> 
  +            [{Key, {boss_to_mongo_op(Operator), Value}}]
  +    end,
  +%    ?LOG("Condition", Condition),
  +    build_conditions1(Rest, lists:append(Condition, Acc)).
  +
   
   proplist_to_tuple(PropList) ->
       ListOfLists = lists:reverse([[K,V]||{K,V} <- PropList]),
  
positive.code:         true ->
              Collection = type_to_collection(Type),
              Res = execute(Conn, fun() ->
                      mongo:find(Collection, proplist_to_tuple(Conditions), [],
                                 Skip, Max) 
                  end),
              case Res of
                  {ok, Curs} ->
  
negative.code: count(Conn, Type, Conditions) ->
      Collection = type_to_collection(Type),
      {ok, Count} = execute(Conn, fun() -> 
                  C = build_conditions(Conditions),
  %                ?LOG("Conditions", C),
                  mongo:count(Collection, C)
          end),
  %    ?LOG("Count", Count),
      Count.
  
  counter(Conn, Id) when is_list(Id) ->
  