anchor.diff:  	trunc(bson:at(n, Doc)). % Server returns count as float
   
   %% @doc Create index on collection according to given spec.
  -%%      Allow user to just supply key
  +%%      The key specification is a bson documents with the following fields:
  +%%      key      :: bson document, for e.g. {field, 1, other, -1, location, 2d}, <strong>required</strong>
  +%%      name     :: bson:utf8()
  +%%      unique   :: boolean()
  +%%      dropDups :: boolean()
   -spec create_index (collection(), bson:document()) -> ok.
   create_index(Coll, IndexSpec) ->
   	#context{database = Database} = erlang:get(mongo_action_context),
  -	Index = bson:update(ns, mongo_protocol:dbcoll(Database, Coll), make_index(IndexSpec)),
  +	Key = bson:at(key, IndexSpec),
  +	Defaults = {name, gen_index_name(Key), unique, false, dropDups, false},
  +	Index = bson:update(ns, mongo_protocol:dbcoll(Database, Coll), bson:merge(IndexSpec, Defaults)),
   	insert('system.indexes', Index).
   
   %% @doc Execute given MongoDB command and return its result.
  
positive.code: 	command/1,
  	create_index/2
  ]).
  
  %-export ([auth/2]).
  %-export ([add_user/3]).
  %-export ([create_index/2]).
  %-export ([copy_database/3, copy_database/5]).
  
  -include("mongo_protocol.hrl").
  
  
negative.code: assign_id(Doc) ->
  	case bson:lookup('_id', Doc) of
  		{_Value} -> Doc;
  		{} -> bson:update('_id', mongo_id_server:object_id(), Doc)
  	end.
  
  %% @private
  gen_index_name(KeyOrder) ->
  	bson:doc_foldl(fun(Label, Order, Acc) ->
  		<<Acc/binary, $_, (value_to_binary(Label))/binary, $_, (value_to_binary(Order))/binary>>
  	end, <<"i">>, KeyOrder).
  
  %% @private
  value_to_binary(Value) when is_integer(Value) ->
  	bson:utf8(integer_to_list(Value));
  value_to_binary(Value) when is_atom(Value) ->
  	atom_to_binary(Value, utf8);
  value_to_binary(Value) when is_binary(Value) ->
  	Value;
  value_to_binary(_Value) ->
  	<<>>.
  
  %% @private
  write(Request) ->
  