@@ -710,12 +710,17 @@ Aggregate.prototype.redact = function(expression, thenExpr, elseExpr) {
710
710
*
711
711
* Model.aggregate(..).explain(callback)
712
712
*
713
+ * @param {String } verbosity
713
714
* @param {Function } callback
714
715
* @return {Promise }
715
716
*/
716
717
717
- Aggregate . prototype . explain = function ( callback ) {
718
+ Aggregate . prototype . explain = function ( verbosity , callback ) {
718
719
const model = this . _model ;
720
+ if ( typeof verbosity === 'function' ) {
721
+ callback = verbosity ;
722
+ verbosity = null ;
723
+ }
719
724
720
725
return promiseOrCallback ( callback , cb => {
721
726
if ( ! this . _pipeline . length ) {
@@ -733,24 +738,34 @@ Aggregate.prototype.explain = function(callback) {
733
738
} ) ;
734
739
}
735
740
736
- this . options . explain = true ;
737
-
738
741
model . collection . aggregate ( this . _pipeline , this . options , ( error , cursor ) => {
739
742
if ( error != null ) {
740
743
const _opts = { error : error } ;
741
744
return model . hooks . execPost ( 'aggregate' , this , [ null ] , _opts , error => {
742
745
cb ( error ) ;
743
746
} ) ;
744
747
}
745
- cursor . explain ( ( error , result ) => {
746
- const _opts = { error : error } ;
747
- return model . hooks . execPost ( 'aggregate' , this , [ result ] , _opts , error => {
748
- if ( error ) {
749
- return cb ( error ) ;
750
- }
751
- return cb ( null , result ) ;
748
+ if ( verbosity != null ) {
749
+ cursor . explain ( verbosity , ( error , result ) => {
750
+ const _opts = { error : error } ;
751
+ return model . hooks . execPost ( 'aggregate' , this , [ result ] , _opts , error => {
752
+ if ( error ) {
753
+ return cb ( error ) ;
754
+ }
755
+ return cb ( null , result ) ;
756
+ } ) ;
752
757
} ) ;
753
- } ) ;
758
+ } else {
759
+ cursor . explain ( ( error , result ) => {
760
+ const _opts = { error : error } ;
761
+ return model . hooks . execPost ( 'aggregate' , this , [ result ] , _opts , error => {
762
+ if ( error ) {
763
+ return cb ( error ) ;
764
+ }
765
+ return cb ( null , result ) ;
766
+ } ) ;
767
+ } ) ;
768
+ }
754
769
} ) ;
755
770
} ) ;
756
771
} , model . events ) ;
0 commit comments