Where i can find examples of mongodb-erlang usage ? The only source of information i found is this file: https://github.com/TonyGen/mongodb-erlang/blob/master/src/mongodb_tests.erl But it not covers many of basic queries like following (picked from MongoDB site):
db.collection.find().sort({name : 1, age: -1}).limit(10);
db.users.find().skip(20).limit(10);
db.things.ensureIndex({j:1});
db.things.find({colors : {$ne : "red"}});
db.collection.find({ "field" : { $gte: value } } );
db.things.find( { "x.a" : 1, "x.b" : { $gt : 1 } } )
So how to write these queries in terms of erlang driver ?
I have this similar issues too, here is my resolution with the offical mongodb-erlang driver:
1.The test mongodb records:
2.How to implement "db.erltest.find({x:{$gt:2}})" via mongodb-erlang?
Summaries:
Cursor = mongo_query:find(DbConn, #'query'{collection=erltest, selector={x, {'$gt', 2}}})
is the detailed implement.For the officially supported driver the API is documented here:
http://api.mongodb.org/erlang/mongodb/
For the find operations check out the function index, specifically:
http://api.mongodb.org/erlang/mongodb/mongo.html#find-2
If that is not to your taste, you may want to also check out the community drivers:
emongo/erlmongo - their respective READMEs and docs have some examples too:
https://bitbucket.org/rumataestor/emongo
https://github.com/wpntv/erlmongo