anchor.diff:  	command/1,
   	create_index/2
   ]).
  -
  -%-export ([auth/2]).
  -%-export ([add_user/3]).
  -%-export ([create_index/2]).
  -%-export ([copy_database/3, copy_database/5]).
  +% TODO: add auth/2
   
   -include("mongo_protocol.hrl").
   
  
positive.code: 	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
  -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)),
  	insert('system.indexes', Index).
  
  %% @doc Execute given MongoDB command and return its result.
  
negative.code: %% @private
  write(Connection, Database, Request, GetLastErrorParams) ->
  	ok = mongo_connection:request(Connection, Database, Request),
  	{0, [Doc | _]} = mongo_connection:request(Connection, Database, #'query'{
  		batchsize = -1,
  		collection = '$cmd',
  		selector = bson:append({getlasterror, 1}, GetLastErrorParams)
  	}),
  	Doc.
  
  %% @private
  read(Request) ->
  	#context{connection = Connection, database = Database, read_mode = ReadMode} = erlang:get(mongo_action_context),
  	#'query'{collection = Collection, batchsize = BatchSize} = Request,
  	{Cursor, Batch} = mongo_connection:request(Connection, Database, Request#'query'{slaveok = ReadMode =:= slave_ok}),
  	mongo_cursor:create(Connection, Database, Collection, Cursor, BatchSize, Batch).
  
  %% @private
  read_one(Request) ->
  	#context{connection = Connection, database = Database, read_mode = ReadMode} = erlang:get(mongo_action_context),
  	{0, Docs} = mongo_connection:request(Connection, Database, Request#'query'{batchsize = -1, slaveok = ReadMode =:= slave_ok}),
  	case Docs of
  		[] -> {};
  		[Doc | _] -> {Doc}
  	end.
  
  