Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added options parameter for ensureIndex

  • Loading branch information...
commit 00e6c3f7ed1ab10b1d49cef6ab7aa59781a76058 1 parent 0a146b8
@SergejJurecko authored
Showing with 9 additions and 6 deletions.
  1. +9 −6 src/mongoapi.erl
View
15 src/mongoapi.erl
@@ -310,19 +310,22 @@ translateopts(H,_, [], L) ->
% If you wish to index on an embedded document, use proplists.
% Example: ensureIndex(<<"mydoc">>, [{<<"name">>, 1}]).
+% ensureIndex(<<"mydoc">>,[{<<"name",1}],[{"unique",true}]).
% You can use lists, they will be turned into binaries.
-ensureIndex([_|_] = Collection, Keys) ->
- ensureIndex(list_to_binary(Collection), Keys);
-ensureIndex(<<_/binary>> = Collection, Keys) ->
+ensureIndex(Collection, Keys) ->
+ ensureIndex(Collection,Keys,[]).
+ensureIndex([_|_] = Collection, Keys,Opts) ->
+ ensureIndex(list_to_binary(Collection), Keys,Opts);
+ensureIndex(<<_/binary>> = Collection, Keys,Opts) ->
Bin = mongodb:encode([{plaintext, <<"name">>, mongodb:gen_prop_keyname(Keys, <<>>)},
{plaintext, <<"ns">>, name(Collection)},
- {<<"key">>, {bson, mongodb:encode(Keys)}}]),
+ {<<"key">>, {bson, mongodb:encode(Keys)}}|Opts]),
mongodb:ensureIndex(Pool,DB, Bin);
% Example: ensureIndex(#mydoc{}, [{#mydoc.name, 1}])
-ensureIndex(Rec, Keys) ->
+ensureIndex(Rec, Keys,Opts) ->
Bin = mongodb:encode([{plaintext, <<"name">>, mongodb:gen_keyname(Rec, Keys)},
{plaintext, <<"ns">>, name(element(1,Rec))},
- {<<"key">>, {bson, mongodb:encoderec_selector(Rec, Keys)}}]),
+ {<<"key">>, {bson, mongodb:encoderec_selector(Rec, Keys)}}|Opts]),
mongodb:ensureIndex(Pool,DB, Bin).
deleteIndexes([_|_] = Collection) ->
Please sign in to comment.
Something went wrong with that request. Please try again.