Commits

Anonymous committed 6bb9727

make orderby work on mongodb 1.4.4

  • Participants
  • Parent commits 8b44754

Comments (0)

Files changed (2)

     QueryRec#emo_query{q=QueryDoc};
 
 create_query([], QueryRec, [], OptDoc) ->
-    QueryRec#emo_query{q=OptDoc};
+    QueryRec#emo_query{q=(OptDoc ++ [{<<"$query">>, [{none, none}]}])};
 
 create_query([], QueryRec, QueryDoc, OptDoc) ->
-    QueryRec#emo_query{q=(OptDoc ++ [{<<"query">>, QueryDoc}])};
+    QueryRec#emo_query{q=(OptDoc ++ [{<<"$query">>, QueryDoc}])};
 
 create_query([{limit, Limit}|Options], QueryRec, QueryDoc, OptDoc) ->
     QueryRec1 = QueryRec#emo_query{limit=Limit},
 
 create_query([{orderby, Orderby}|Options], QueryRec, QueryDoc, OptDoc) ->
     Orderby1 = [{Key, case Dir of desc -> -1; _ -> 1 end}|| {Key, Dir} <- Orderby],
-    OptDoc1 = [{<<"orderby">>, Orderby1}|OptDoc],
+    OptDoc1 = [{<<"$orderby">>, Orderby1}|OptDoc],
     create_query(Options, QueryRec, QueryDoc, OptDoc1);
 
 create_query([{fields, Fields}|Options], QueryRec, QueryDoc, OptDoc) ->

src/emongo_bson.erl

 encode([{_,_}|_]=List) when is_list(List) ->
 	Bin = iolist_to_binary([encode_key_value(Key, Val) || {Key, Val} <- List]),
 	<<(size(Bin)+5):32/little-signed, Bin/binary, 0:8>>.
+
+encode_key_value(none, none) ->
+    <<>>;
 		
 %% FLOAT
 encode_key_value(Key, Val) when is_float(Val) ->