Open tshemsedinov opened 7 years ago
Preprocess:
{ name: 'Marcus' }
to { name: ['=', 'Marcus'] }
{ name: '!Marcus' }
to { name: ['!', 'Marcus'] }
{ age: '>20' }
to { age: ['>', '20'] }
{ score: '200..500' }
to { score: [ ['>=', 200], ['<=', 500] ] }
Convert to MongoDB syntax:
{ name: ['!', 'Marcus'] }
to { name: { $ne: 'Marcus' } }
{ age: ['>', '20'] }
to { age: { $gt: 20 } }
{ age: ['<', '20'] }
to { age: { $lt: 20 } }
{ age: ['>=', '20'] }
to { age: { $gte: 20 } }
{ age: ['<=', '20'] }
to { age: { $lte: 20 } }
{ score: [ ['>=', 200], ['<=', 500] ] }
to { score: { $gt: 200, $lt: 500 } }
{ city: ['Kiev', 'Roma'] }
to { city: { $in: ['Kiev', 'Roma'] } }
{ city: { not: ['Kiev', 'Roma'] } }
to { city: { $nin: ['Kiev', 'Roma'] } }
We have following syntax for
Cursor.filter(fn)
:But we need also declarative comparison operators for
Category.find(query)
andCursor.find(query)
===
Equal to{ field: value }
!==
Not equal to{ field: '!value' }
>
Greater than{ field: '>value' }
<
Less than{ field: '<value' }
>=
Greater than or equal to{ field: '>=value' }
<=
Less than or equal to{ field: '<=value' }
{ field: 'from..to' }
{ age: '>20', city: 'Odessa' }
[ { age: '>20' }, { city: 'Odessa' } ]