, mongodb-erlang:
1. mongodb :
>db.erltest.find()
{ "_id" : ObjectId("4fe80d692f6cc055a32da380"), "x" : 1, "y" : 2 }
{ "_id" : ObjectId("4fe80d702f6cc055a32da381"), "x" : 2, "y" : 3 }
{ "_id" : ObjectId("4fe80d762f6cc055a32da382"), "x" : 10, "y" : 3 }
{ "_id" : ObjectId("4fe80d7e2f6cc055a32da383"), "x" : 10, "y" : 4 }
2. "db.erltest.find({x: {$ gt: 2}})" mongodb-erlang?
-module(mongo_test2).
-export([tmp_test/0]).
-include ("/opt/Erlang/lib/erlang/lib/mongodb-master/include/mongo_protocol.hrl").
tmp_test() ->
application:start(mongodb),
Host = {localhost, 27017},
{ok, Conn} = mongo:connect(Host),
io:format("Conn is : ~p~n", [Conn]),
DbConn = {test, Conn},
Cursor = mongo_query:find(DbConn, #'query'{collection=erltest, selector={x, {'$gt', 2}}}),
process(Cursor),
mongo:disconnect(Conn).
process({}) ->
ok;
process(Cursor) ->
io:format("----Cursor:~p~n", [Cursor]),
Record = mongo:next(Cursor),
io:format("Record:~p~n", [Record]),
case Record of
{} ->
no_more;
_ ->
process(Cursor)
end.
:
- , * mongo_protocol.hrl *.
Cursor = mongo_query:find(DbConn, #'query'{collection=erltest, selector={x, {'$gt', 2}}}) - .- , mongodb_test.erl .
- -, , , , , :)