@@ -655,6 +655,10 @@ export class MongoDriver implements DriverContract {
655
655
return this
656
656
}
657
657
658
+ if ( statement . _id && Is . String ( statement . _id ) ) {
659
+ statement . _id = new ObjectID ( statement . _id )
660
+ }
661
+
658
662
this . _where = {
659
663
...this . _where ,
660
664
...statement ,
@@ -670,12 +674,20 @@ export class MongoDriver implements DriverContract {
670
674
value ?: any ,
671
675
) : DriverContract {
672
676
if ( typeof statement === 'string' ) {
677
+ if ( isValidObjectId ( value ) && Is . String ( value ) ) {
678
+ value = new ObjectID ( value )
679
+ }
680
+
673
681
this . _where [ statement ] = { $regex : value }
674
682
this . _pipeline . push ( { $match : this . _where } )
675
683
676
684
return this
677
685
}
678
686
687
+ if ( statement . _id && Is . String ( statement . _id ) ) {
688
+ statement . _id = new ObjectID ( statement . _id )
689
+ }
690
+
679
691
this . _where = {
680
692
...this . _where ,
681
693
...statement ,
@@ -689,12 +701,20 @@ export class MongoDriver implements DriverContract {
689
701
value ?: any ,
690
702
) : DriverContract {
691
703
if ( typeof statement === 'string' ) {
704
+ if ( isValidObjectId ( value ) && Is . String ( value ) ) {
705
+ value = new ObjectID ( value )
706
+ }
707
+
692
708
this . _where [ statement ] = { $regex : value , $options : 'i' }
693
709
this . _pipeline . push ( { $match : this . _where } )
694
710
695
711
return this
696
712
}
697
713
714
+ if ( statement . _id && Is . String ( statement . _id ) ) {
715
+ statement . _id = new ObjectID ( statement . _id )
716
+ }
717
+
698
718
this . _where = {
699
719
...this . _where ,
700
720
...statement ,
@@ -710,12 +730,20 @@ export class MongoDriver implements DriverContract {
710
730
value ?: any ,
711
731
) : DriverContract {
712
732
if ( typeof statement === 'string' ) {
733
+ if ( isValidObjectId ( value ) && Is . String ( value ) ) {
734
+ value = new ObjectID ( value )
735
+ }
736
+
713
737
this . _where [ statement ] = { $or : value }
714
738
this . _pipeline . push ( { $match : this . _where } )
715
739
716
740
return this
717
741
}
718
742
743
+ if ( statement . _id && Is . String ( statement . _id ) ) {
744
+ statement . _id = new ObjectID ( statement . _id )
745
+ }
746
+
719
747
this . _where = {
720
748
...this . _where ,
721
749
...statement ,
@@ -730,12 +758,20 @@ export class MongoDriver implements DriverContract {
730
758
value ?: any ,
731
759
) : DriverContract {
732
760
if ( typeof statement === 'string' ) {
761
+ if ( isValidObjectId ( value ) && Is . String ( value ) ) {
762
+ value = new ObjectID ( value )
763
+ }
764
+
733
765
this . _where [ statement ] = { $not : value }
734
766
this . _pipeline . push ( { $match : this . _where } )
735
767
736
768
return this
737
769
}
738
770
771
+ if ( statement . _id && Is . String ( statement . _id ) ) {
772
+ statement . _id = new ObjectID ( statement . _id )
773
+ }
774
+
739
775
this . _where = {
740
776
...this . _where ,
741
777
...statement ,
@@ -746,13 +782,33 @@ export class MongoDriver implements DriverContract {
746
782
}
747
783
748
784
buildWhereIn ( columnName : string , values : any [ ] ) : DriverContract {
785
+ if ( columnName === '_id' ) {
786
+ values = values . map ( value => {
787
+ if ( Is . String ( value ) ) {
788
+ return new ObjectID ( value )
789
+ }
790
+
791
+ return value
792
+ } )
793
+ }
794
+
749
795
this . _where [ columnName ] = { $in : values }
750
796
this . _pipeline . push ( { $match : this . _where } )
751
797
752
798
return this
753
799
}
754
800
755
801
buildWhereNotIn ( columnName : string , values : any [ ] ) : DriverContract {
802
+ if ( columnName === '_id' ) {
803
+ values = values . map ( value => {
804
+ if ( Is . String ( value ) ) {
805
+ return new ObjectID ( value )
806
+ }
807
+
808
+ return value
809
+ } )
810
+ }
811
+
756
812
this . _where [ columnName ] = { $nin : values }
757
813
this . _pipeline . push ( { $match : this . _where } )
758
814
@@ -788,13 +844,33 @@ export class MongoDriver implements DriverContract {
788
844
}
789
845
790
846
buildWhereBetween ( columnName : string , values : [ any , any ] ) : DriverContract {
847
+ if ( columnName === '_id' ) {
848
+ if ( Is . String ( values [ 0 ] ) ) {
849
+ values [ 0 ] = new ObjectID ( values [ 0 ] )
850
+ }
851
+
852
+ if ( Is . String ( values [ 1 ] ) ) {
853
+ values [ 1 ] = new ObjectID ( values [ 1 ] )
854
+ }
855
+ }
856
+
791
857
this . _where [ columnName ] = { $gte : values [ 0 ] , $lte : values [ 1 ] }
792
858
this . _pipeline . push ( { $match : this . _where } )
793
859
794
860
return this
795
861
}
796
862
797
863
buildWhereNotBetween ( columnName : string , values : [ any , any ] ) : DriverContract {
864
+ if ( columnName === '_id' ) {
865
+ if ( Is . String ( values [ 0 ] ) ) {
866
+ values [ 0 ] = new ObjectID ( values [ 0 ] )
867
+ }
868
+
869
+ if ( Is . String ( values [ 1 ] ) ) {
870
+ values [ 1 ] = new ObjectID ( values [ 1 ] )
871
+ }
872
+ }
873
+
798
874
this . _where [ columnName ] = { $not : { $gte : values [ 0 ] , $lte : values [ 1 ] } }
799
875
this . _pipeline . push ( { $match : this . _where } )
800
876
@@ -904,6 +980,10 @@ export class MongoDriver implements DriverContract {
904
980
}
905
981
906
982
buildHaving ( column : string , operator : string , value : any ) : DriverContract {
983
+ if ( column === '_id' && Is . String ( value ) ) {
984
+ value = new ObjectID ( value )
985
+ }
986
+
907
987
const operatorDictionary = {
908
988
'>=' : { $gte : value } ,
909
989
'<=' : { $lte : value } ,
0 commit comments