@@ -531,17 +531,51 @@ Query.prototype.slice = function() {
531
531
*/
532
532
533
533
/**
534
- * Specifies a `$mod` condition
534
+ * Specifies a `$mod` condition, filters documents for documents whose
535
+ * `path` property is a number that is equal to `remainder` modulo `divisor`.
536
+ *
537
+ * ####Example
538
+ *
539
+ * // All find products whose inventory is odd
540
+ * Product.find().mod('inventory', [2, 1]);
541
+ * Product.find().where('inventory').mod([2, 1]);
542
+ * // This syntax is a little strange, but supported.
543
+ * Product.find().where('inventory').mod(2, 1);
535
544
*
536
545
* @method mod
537
546
* @memberOf Query
538
547
* @param {String } [path]
539
- * @param {Number } val
548
+ * @param {Array } val must be of length 2, first element is `divisor`, 2nd element is `remainder`.
540
549
* @return {Query } this
541
550
* @see $mod http://docs.mongodb.org/manual/reference/operator/mod/
542
551
* @api public
543
552
*/
544
553
554
+ Query . prototype . mod = function ( ) {
555
+ var val ;
556
+ var path ;
557
+
558
+ if ( arguments . length === 1 ) {
559
+ this . _ensurePath ( 'mod' ) ;
560
+ val = arguments [ 0 ] ;
561
+ path = this . _path ;
562
+ } else if ( arguments . length === 2 && ! Array . isArray ( arguments [ 1 ] ) ) {
563
+ this . _ensurePath ( 'mod' ) ;
564
+ val = slice ( arguments ) ;
565
+ path = this . _path ;
566
+ } else if ( arguments . length === 3 ) {
567
+ val = slice ( arguments , 1 ) ;
568
+ path = arguments [ 0 ] ;
569
+ } else {
570
+ val = arguments [ 1 ] ;
571
+ path = arguments [ 0 ] ;
572
+ }
573
+
574
+ var conds = this . _conditions [ path ] || ( this . _conditions [ path ] = { } ) ;
575
+ conds . $mod = val ;
576
+ return this ;
577
+ } ;
578
+
545
579
/**
546
580
* Specifies an `$exists` condition
547
581
*
0 commit comments