2

I looked for this query in Chicagoboss API, but could not find any solution to write a "OR" query. I have to write a query something like:

select * from TableName where  table.key1 = "XXXX1" OR   table.key2 = "XXXX2"

Here is my chicagoboss query, I want to check if any of the three flags is true then do something with heirs.

Heirs = boss_db:find(heir, [{flag1, 'equals', true}, {flag2, 'equals', true},
                            {flag3, 'equals', true}], [{order_by, code}]).

To execute this, Is there something like:

Heirs = boss_db:find(heir, [{{flag1, 'equals', true}, orelse, {flag2, 'equals', true}, orelse, {flag3, 'equals', true}}], [{order_by, code}]).

2 Answers2

2

Based on the documentation and the source code of boss_db.erl, find/3 seems to return records matching all of the given conditions.

You should file an issue on GitHub.

A workaround exists for SQL databases (use undocumented function boss_db:find_by_sql/3), but none for MongoDB which you seem to use because of the tag. So you will have to fetch the records through several calls.

Paul Guyot
  • 6,257
  • 1
  • 20
  • 31
  • 1
    Thanks for the suggestions! I have raised and issue https://github.com/ChicagoBoss/boss_db/issues/185. –  Jul 11 '14 at 12:21
  • However let us wait, if someone would like to comment something more. Will accept your answer in two days. Don't mind bro. –  Jul 11 '14 at 12:40
1

you can use some like this:

Var = case boss_db:find(heir,[{flag1, 'equals', true}]) of 
        Data -> Data;
        [] -> case boss_db:find(heir,[{flag2, 'equals', true}]) of 
                   Data -> Data;
                   [] -> "no data" 
              end 
      end.
7i11
  • 96
  • 6