File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -200,4 +200,22 @@ export class Query extends BaseQuery {
200
200
this . _parameters [ key ] = { '$nin' : value } ;
201
201
return this ;
202
202
}
203
+
204
+ /**
205
+ * @method notExists
206
+ * @memberof Query
207
+ * @description Returns the raw (JSON) query based on the filters applied on Query object.
208
+ * @example
209
+ * import contentstack from '@contentstack/delivery-sdk'
210
+ *
211
+ * const stack = contentstack.Stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
212
+ * const query = stack.contentType("contentTypeUid").Query();
213
+ * const result = notExists('fieldUid').find()
214
+ *
215
+ * @returns {Query }
216
+ */
217
+ notExists ( key : string ) : Query {
218
+ this . _parameters [ key ] = { '$exists' : false } ;
219
+ return this ;
220
+ }
203
221
}
Original file line number Diff line number Diff line change @@ -46,6 +46,17 @@ describe('ContentType Query API test cases', () => {
46
46
expect ( query . entries [ 0 ] . created_at ) . toBeDefined ( ) ;
47
47
}
48
48
} ) ;
49
+
50
+ it ( 'should get entries which does not match the fieldUid - notExists' , async ( ) => {
51
+ const query = await makeContentType ( 'contenttype_uid' ) . Query ( ) . notExists ( 'multi_line' ) . find < TEntry > ( )
52
+ if ( query . entries ) {
53
+ expect ( query . entries [ 0 ] . _version ) . toBeDefined ( ) ;
54
+ expect ( query . entries [ 0 ] . title ) . toBeDefined ( ) ;
55
+ expect ( query . entries [ 0 ] . uid ) . toBeDefined ( ) ;
56
+ expect ( query . entries [ 0 ] . created_at ) . toBeDefined ( ) ;
57
+ expect ( ( query . entries [ 0 ] as any ) . multi_line ) . not . toBeDefined ( )
58
+ }
59
+ } ) ;
49
60
} ) ;
50
61
function makeContentType ( uid = '' ) : ContentType {
51
62
const contentType = stack . ContentType ( uid ) ;
Original file line number Diff line number Diff line change @@ -58,10 +58,14 @@ describe('ContentType Query class', () => {
58
58
} ) ;
59
59
it ( 'should get entries which matches the fieldUid and values' , ( ) => {
60
60
const query = contentType . Query ( ) . containedIn ( 'fieldUID' , [ 'value' ] ) ;
61
- expect ( query . _queryParams ) . toStrictEqual ( { 'fieldUID' : { '$in' : [ 'value' ] } } ) ;
61
+ expect ( query . _parameters ) . toStrictEqual ( { 'fieldUID' : { '$in' : [ 'value' ] } } ) ;
62
62
} ) ;
63
63
it ( 'should get entries which does not match the fieldUid and values' , ( ) => {
64
64
const query = contentType . Query ( ) . notContainedIn ( 'fieldUID' , [ 'value' , 'value2' ] ) ;
65
- expect ( query . _queryParams ) . toStrictEqual ( { 'fieldUID' : { '$nin' : [ 'value' , 'value2' ] } } ) ;
65
+ expect ( query . _parameters ) . toStrictEqual ( { 'fieldUID' : { '$nin' : [ 'value' , 'value2' ] } } ) ;
66
+ } ) ;
67
+ it ( 'should get entries which does not match the fieldUid - notExists' , ( ) => {
68
+ const query = contentType . Query ( ) . notExists ( 'fieldUID' ) ;
69
+ expect ( query . _parameters ) . toStrictEqual ( { 'fieldUID' : { '$exists' : false } } ) ;
66
70
} ) ;
67
71
} ) ;
You can’t perform that action at this time.
0 commit comments