Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added nested query tests and documentation

  • Loading branch information...
commit d2b4bf837116fb8cd0a44601a84c49bb392c7354 1 parent 6ffab3d
Jacob Vorreuter authored
Showing with 28 additions and 1 deletion.
  1. +8 −1 README.markdown
  2. +11 −0 t/003-find.t
  3. +9 −0 t/004-cond-exprs.t
View
9 README.markdown
@@ -138,4 +138,11 @@ __exists__
__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"}]).
View
11 t/003-find.t
@@ -49,5 +49,16 @@ main(_) ->
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().
View
9 t/004-cond-exprs.t
@@ -98,4 +98,13 @@ main(_) ->
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().
Please sign in to comment.
Something went wrong with that request. Please try again.