Initialize
# Pass JSON object array
var Movie = JsonQuery(movies);
Operators
$eq, $ne, $lt, $gt, $bt, $in, $ni, $li(regex)
Equal
Movie.where({'rating': 8.4})Run
#or
Movie.where({'rating.$eq': 8.4})Run
# not equal
Movie.where({'rating.$ne': 8.4})Run
Like
Movie.where({'name.$li': 'Godfather'})Run
#or using regex
Movie.where({'name.$li': /godfather/i})Run
Between
Movie.where({'rating.$bt': [8, 9]})Run
Less than, greater than
# greater than
Movie.where({'rating.$gt': 7})Run
# less than
Movie.where({'rating.$lt': 8.4})Run
In
# in
Movie.where({'rating.$in': [8.4, 7.4]})Run
# not in
Movie.where({'rating.$ni': [8.4, 7.3]})Run
Combine multiple criteria
Movie.where({'rating': 8.4, 'name.$li': /braveheart/i})Run
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 })Run
#OR query. It must used with where.
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).or({'rating': 8.4}).exec();Run
all, groupBy, select, pluck, limit and offset, order
Movie.allRun
Movie.firstRun
Movie.lastRun
Movie.groupBy('rating').exec()Run
Movie.select('actor', 'rating').exec()Run
Movie.pluck('actor').exec()Run
Movie.limit(10).offset(20).exec()Run
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).allRun
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).firstRun
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).groupBy('rating').exec()Run
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).select('actor', 'rating').exec()Run
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).pluck('actor').exec()Run
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).limit(10).offset(20).exec()Run
# Order : desc / asc
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).order({'rating': 'desc'}).exec()Run
Movie.order({'rating': 'desc', actor: 'asc'}).exec()Run
# Unique
Movie.uniq('rating').exec()Run
Movie.where({'actor': 'Al Pacino', 'year.$gt': 1970 }).uniq('rating').exec()Run
Movie.uniq('rating').pluck('rating').exec()Run
# Find - will return first record
# Default id field is `id`. If id field otherthen `id` then set "Movie = JsonQuery(movies, {'id': '_id'})"
Movie.find(10)Run
Movie.find('rating', 8.4)Run