0

I'm a new one in ChicagoBoss and Erlang. And I have dumb question: How can I get last entity from db? Something like User.last in Rails.

cnaize
  • 3,139
  • 5
  • 27
  • 45

1 Answers1

1

You can use find_last BossDB function:

boss_db:find_last(type).

Query for the last BossRecord of type type

boss_db:find_last(type, [{foo, 'equals', <<"abc">>}, {bar, 'equals', 123}]).

Query for the last BossRecord of type type matching all of the given conditions.

Full API: http://www.chicagoboss.org/api-db.html

P_A
  • 1,804
  • 1
  • 19
  • 33
  • From the web page you linked: "Currently Tokyo Tyrant, Mnesia, MySQL, and PostgreSQL are supported." The question was about MongoDB. – WiredPrairie Dec 06 '13 at 20:44
  • From BossDB github page (https://github.com/ChicagoBoss/boss_db): "Supported databases: NEW DynamoDB (experimental), Mnesia, **MongoDB**, MySQL, PostgreSQL, Riak, Tokyo Tyrant". I used BossDB with MongoDB in my project and this is worked fine. – P_A Dec 06 '13 at 22:10
  • From the library: `find_last(Type) -> return_one(find(Type, [], [{limit, 1}, descending])).` Nicely matches what I'd said needed to be done in my first comment. :) Also -- to note, if a field is chosen that isn't sorted already, MongoDB must sort in memory, which may be slow, depending on the size of the collection. – WiredPrairie Dec 06 '13 at 22:19
  • Yes, of course your first comment is right :) I just showed which function does it. – P_A Dec 06 '13 at 22:28