Yan
Yan

Reputation: 81

Query return wrong result using mongdb erlang driver?

When I tried

Query = {country, <<"US">>}, mongo:find(Col, { '$query', Query, '$orderby', {last_seen, -1} }, Projector, 0, 15),

The cursor returned is not limited to batch size 15 any more. It will return all the results in cursor. However, if I change it to

mongo:find(Col, Query, Projector, 0, 15),

It will return the cursor with 15 in size.

Is this a bug or I did anything wrong?

Upvotes: 1

Views: 952

Answers (1)

Tony Hannan
Tony Hannan

Reputation: 81

It works for me on example below

run () ->
    application:start (mongodb),
    {ok, Conn} = mongo:connect (localhost),
    {ok, Docs} = mongo:do (safe, master, Conn, test, fun() ->
        mongo:delete (foo, {}),
        mongo:insert_all (foo, [{x,1}, {x,2}, {x,3}, {x,0}, {x,-1}]),
        Cur = mongo:find (foo, {'$query', {}, '$orderby', {x,1}}, {'_id',0}, 0, 3),
        mongo:rest (Cur) end),
    mongo:disconnect (Conn),
    [{x,-1}, {x,0}, {x,1}] = Docs.

Upvotes: 2

Related Questions