Commits

Anonymous committed ebdea1d

added nested query tests and documentation

Comments (0)

Files changed (3)

 __where__
 
 	%% find documents where the value of field1 is greater than 10
-	emongo:find(test, "collection", [{where, "this.field1 > 10"}]).
+	emongo:find(test, "collection", [{where, "this.field1 > 10"}]).
+	
+__nested queries__
+
+	%% find documents with an address field containing a sub-document containing
+	%% a street field equalling "Maple Drive".
+	%% ie: [{"address", [{"street", "Maple Drive"}, {"zip", 94114}]
+	emongo:find(test, "people", [{"address.street", "Maple Drive"}]).
 		etap:is(proplists:get_value(<<"rolls">>, hd(Docs)), 100, "query returned correct value"),
 		ok
 	end)(),
+	
+	%% NESTED QUERIES
+	[emongo:insert(test1, "sushi", [{<<"seaweed">>, [{<<"sheets">>, I}]}]) || I <- lists:seq(1,10)],
+	
+	(fun() ->
+		Docs = emongo:find(test1, "sushi", [{"seaweed.sheets", 5}]),
+		etap:is(length(Docs), 1, "correct number of results from nested query"),
+		etap:is(proplists:get_value(<<"seaweed">>, hd(Docs)), [{<<"sheets">>, 5}], "correct result returned"),
+		ok
+	end)(),
+	
 
    	etap:end_tests().

t/004-cond-exprs.t

 		ok
 	end)(),
 	
+	[emongo:insert(test1, "sushi", [{<<"seaweed">>, [{<<"sheets">>, I}]}]) || I <- lists:seq(1,10)],
+	
+	(fun() ->
+		Docs = emongo:find(test1, "sushi", [{"seaweed.sheets", [{in, [3,4,5]}]}]),
+		etap:is(length(Docs), 3, "correct number of results from nested query"),
+		etap:is([I || [_, {<<"seaweed">>, [{<<"sheets">>, I}]}] <- Docs], [3,4,5], "correct results from where query"),
+		ok
+	end)(),
+	
    	etap:end_tests().