avejidah

Condition BNF

Aug 25th, 2015
665
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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]}}]}]}
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×