Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
add search and query test, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
comtihon committed Jul 30, 2014
1 parent 82218bc commit 82e3199
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -90,7 +90,8 @@ For filtering result - use `Projector`:
will return one document from collection Collection with fetching `only` _id and value.

mongo:find_one(Connection, Collection, {}, {key, false, value, false}).
will return your data without key and value params. If there is no other data - only _id will be returned.
will return your data without key and value params. If there is no other data - only _id will be returned.
__Important!__ For empty projector use `[]` instead `{}`. For empty selector use `{}`.

### Administering

Expand Down
2 changes: 2 additions & 0 deletions rebar.config
Expand Up @@ -3,6 +3,8 @@
{erl_opts, [debug_info, fail_on_warning]}.
{edoc_opts, [{index_columns, 1}, {sort_functions, false}, {preprocess, true}]}.

{plugins, [rebar_ct]}.

{deps, [
{bson, ".*", {git, "git://github.com/soundrop/bson-erlang", "HEAD"}}
]}.
Expand Down
50 changes: 47 additions & 3 deletions test/mongo_SUITE.erl
@@ -1,22 +1,30 @@
-module(mongo_SUITE).

-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

-include("mongo_protocol.hrl").


-export([
all/0,
init_per_suite/1,
end_per_suite/1,
init_per_testcase/2,
end_per_testcase/2
]).
end_per_testcase/2,
search_and_query/1]).

-export([
insert_and_find/1,
insert_and_delete/1
]).

all() ->
[insert_and_find, insert_and_delete].
[
insert_and_find,
insert_and_delete,
search_and_query
].

init_per_suite(Config) ->
application:start(bson),
Expand Down Expand Up @@ -81,6 +89,42 @@ insert_and_delete(Config) ->
mongo:delete_one(Connection, Collection, {}),
3 = mongo:count(Connection, Collection, {}).

search_and_query(Config) ->
Connection = ?config(connection, Config),
Collection = ?config(collection, Config),

%insert test data
mongo:insert(Connection, Collection, [
{name, <<"Yankees">>, home, {city, <<"New York">>, state, <<"NY">>}, league, <<"American">>},
{name, <<"Mets">>, home, {city, <<"New York">>, state, <<"NY">>}, league, <<"National">>},
{name, <<"Phillies">>, home, {city, <<"Philadelphia">>, state, <<"PA">>}, league, <<"National">>},
{name, <<"Red Sox">>, home, {city, <<"Boston">>, state, <<"MA">>}, league, <<"American">>}
]),

%test selector
Res = find(Connection, Collection, {home, {city, <<"New York">>, state, <<"NY">>}}),
?debugFmt("Got ~p", [Res]),
[{'_id', _,
name, <<"Yankees">>, home,
{city, <<"New York">>, state, <<"NY">>},
league, <<"American">>},
{'_id', _,
name, <<"Mets">>, home,
{city, <<"New York">>, state, <<"NY">>},
league, <<"National">>}] = Res,

%test projector
Res2 = find(Connection, Collection, {home, {city, <<"New York">>, state, <<"NY">>}}, {name, true, league, true}),
?debugFmt("Got ~p", [Res2]),
[{'_id', _,
name, <<"Yankees">>,
league, <<"American">>},
{'_id', _,
name, <<"Mets">>,
league, <<"National">>}] = Res2,

Config.


%% @private
find(Connection, Collection, Selector) ->
Expand Down

0 comments on commit 82e3199

Please sign in to comment.