Advertisement
avejidah

Condition BNF

Aug 25th, 2015
3,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BNF 1.04 KB | None | 0 0
  1. <condition>           ::= <expression> | <expression-list>
  2. <expression>          ::= { <field> : { <comparison-operator> : <value> } }
  3. <expression-list>     ::= { <boolean-operator> : [ <condition> , <condition> {, <condition>} ] }
  4. <pair-comparison>     ::= { <field> : { <comparison-operator> : <value> } }
  5. <array-comparison>    ::= { <field> : { $in : [ <value> {, <value>} ] } }
  6. <comparison-operator> ::= $eq | $neq | $lt | $lte | $gt | $gte
  7. <boolean-operator>    ::= $and | $or
  8. <field>               ::= <text>
  9. <value>               ::= <text> | <number>
  10.  
  11. /****
  12.  * Some examples.
  13. ****/
  14. // `name` = 'Sam'
  15. {name: {$eq: 'Sam'}}
  16.  
  17. // `age` > 21
  18. {age: {$gt: 21}}
  19.  
  20. // `showSize` IN (10, 10.5, 11)
  21. {shoeSize: {$in: [10, 10.5, 11]}}
  22.  
  23. // (`name` = 'Sam' AND `age` > 21 AND showSize IN (10, 10.5, 11))
  24. {$and: [{name: {$eq: 'Sam'}}, {age: {$gt: 21}}, {shoeSize: {$in: [10, 10.5, 11]}}]}
  25.  
  26. // (`name` = 'Sam' AND (`age` > 21 OR showSize IN (10, 10.5, 11)))
  27. {$and: [{name: {$eq: 'Sam'}}, {$or: [{age: {$gt: 21}}, {shoeSize: {$in: [10, 10.5, 11]}}]}]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement