File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -791,6 +791,38 @@ describe('model query casting', function() {
791
791
assert . ok ( res ) ;
792
792
assert . deepStrictEqual ( res . map ( doc => doc . arr [ 1 ] . id ) , [ 'two' , 'three' ] ) ;
793
793
} ) ;
794
+
795
+ it ( 'should not throw a cast error when dealing with an array of objects in combination with $elemMatch and nested $and' , async function ( ) {
796
+ const testSchema = new Schema ( {
797
+ arr : [ Object ]
798
+ } ) ;
799
+
800
+ const Test = db . model ( 'Test' , testSchema ) ;
801
+ const obj1 = new Test ( { arr : [ { id : 'one' , name : 'sample1' } , { id : 'two' } ] } ) ;
802
+ await obj1 . save ( ) ;
803
+
804
+ const obj2 = new Test ( { arr : [ { id : 'two' , name : 'sample1' } , { id : 'three' } ] } ) ;
805
+ await obj2 . save ( ) ;
806
+
807
+ const obj3 = new Test ( { arr : [ { id : 'three' , name : 'sample1' } , { id : 'four' } ] } ) ;
808
+ await obj3 . save ( ) ;
809
+ const res = await Test . find ( {
810
+ arr : {
811
+ $elemMatch : {
812
+ $and : [
813
+ { name : 'sample1' } ,
814
+ { $or : [
815
+ { id : 'one' } ,
816
+ { id : 'two' }
817
+ ] }
818
+ ]
819
+ }
820
+ }
821
+ } ) . sort ( { _id : 1 } ) ;
822
+ assert . ok ( res ) ;
823
+ assert . equal ( res . length , 2 ) ;
824
+ assert . deepStrictEqual ( res . map ( doc => doc . arr [ 1 ] . id ) , [ 'two' , 'three' ] ) ;
825
+ } ) ;
794
826
} ) ;
795
827
796
828
function _geojsonPoint ( coordinates ) {
You can’t perform that action at this time.
0 commit comments