File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ class MongoQuery {
82
82
for ( const key in obj ) {
83
83
if ( ! obj . hasOwnProperty ( key ) ) continue ;
84
84
85
- if ( $check . object ( obj [ key ] ) && ! utils . isValidId ( obj [ key ] ) ) {
85
+ if ( $check . object ( obj [ key ] ) && ! utils . isValidId ( obj [ key ] ) && key !== '$regularExpression' ) {
86
86
mergeRawQueryRecursive ( obj [ key ] , obj , key ) ;
87
87
} else if ( $check . array ( obj [ key ] ) ) {
88
88
for ( let i = 0 ; i < obj [ key ] . length ; i ++ ) {
@@ -114,6 +114,8 @@ class MongoQuery {
114
114
parent [ parentKey ] = queryVal ;
115
115
} else if ( key === '$string' ) {
116
116
parent [ parentKey ] = $check . assigned ( obj [ key ] ) && obj [ key ] . toString ? obj [ key ] . toString ( ) : obj [ key ] ;
117
+ } else if ( key === '$regularExpression' ) {
118
+ parent [ parentKey ] = new RegExp ( obj [ key ] . pattern , obj [ key ] . options ) ;
117
119
}
118
120
}
119
121
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @synatic/mongo-magic" ,
3
- "version" : " 2.3.2 " ,
3
+ "version" : " 2.3.3 " ,
4
4
"description" : " Synatic utility classes for interacting with MongoDB" ,
5
5
"main" : " index.js" ,
6
6
"files" : [
Original file line number Diff line number Diff line change @@ -147,6 +147,19 @@ describe('Mongo Query', function () {
147
147
done ( ) ;
148
148
} ) ;
149
149
150
+ it ( 'should parse a raw query with regularExpression in \'$in\' array' , function ( done ) {
151
+ const mongoQuery = new MongoQuery ( { $rawQuery : {
152
+ field : { $in : [
153
+ { $regularExpression : { pattern : ';' , options : 'i' } } ,
154
+ { $regularExpression : { pattern : '/' , options : 'i' } }
155
+ ] } }
156
+ } ) ;
157
+
158
+ assert ( mongoQuery . parsedQuery . query . field . $in [ 0 ] instanceof RegExp , 'Invalid parsed $in RegExp query' ) ;
159
+ assert ( mongoQuery . parsedQuery . query . field . $in [ 1 ] instanceof RegExp , 'Invalid parsed $in RegExp query' ) ;
160
+ done ( ) ;
161
+ } ) ;
162
+
150
163
it ( 'should parse a raw query with int' , function ( done ) {
151
164
const mongoQuery = new MongoQuery ( { $rawQuery : { 'field1.field2' : { $float : '1.2' } } } ) ;
152
165
You can’t perform that action at this time.
0 commit comments