Commits

Jacob Perkins committed df71817

distinct command with Selector

Comments (0)

Files changed (1)

 		 find_all/2, find_all/3, find_all/4, get_more/4,
 		 get_more/5, find_one/3, find_one/4, kill_cursors/2,
 		 insert/3, update/4, update/5, delete/2, delete/3,
-		 ensure_index/3, count/2, count/3, distinct/3, dec2hex/1, hex2dec/1]).
+		 ensure_index/3, count/2, count/3, distinct/3, distinct/4,
+		 dec2hex/1, hex2dec/1]).
 
 -include("emongo.hrl").
 
 			undefined
 	end.
 
+distinct(PoolId, Collection, Key, []) ->
+	distinct(PoolId, Collection, Key);
+distinct(PoolId, Collection, Key, Selector) ->
+	{Pid, Pool} = gen_server:call(?MODULE, {pid, PoolId}, infinity),
+	Q = [{<<"distinct">>, Collection}, {<<"key">>, Key}, {<<"ns">>, Pool#pool.database},
+		 {<<"query">>, transform_selector(Selector)}],
+	Query = #emo_query{q=Q, limit=1},
+	Packet = emongo_packet:do_query(Pool#pool.database, "$cmd", Pool#pool.req_id, Query),
+	case emongo_server:send_recv(Pid, Pool#pool.req_id, Packet, ?TIMEOUT) of
+		#response{documents=[[{<<"values">>, {array, Vals}} | _]]} ->
+			Vals;
+		_ ->
+			undefined
+	end.
+
 %drop_collection(PoolId, Collection) when is_atom(PoolId), is_list(Collection) ->
 
 %%====================================================================
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.