diff --git a/packages/fhir-qb/index.js b/packages/fhir-qb/index.js index 6b5178d..9aacd63 100644 --- a/packages/fhir-qb/index.js +++ b/packages/fhir-qb/index.js @@ -494,7 +494,7 @@ class QueryBuilder { // If the modifier is 'missing', nothing else matters, we're just checking if the field exists. if (modifier === matchModifiers.missing) { value = sanitize.sanitizeBoolean({ field, value }); - subQuery = this.qb.buildExistsQuery({ field, exists: value }); + subQuery = this.qb.buildExistsQuery({ field, exists: !value }); } else { // Otherwise, construct a query based on data type switch (type) { diff --git a/packages/fhir-qb/index.test.js b/packages/fhir-qb/index.test.js index ced2ca8..9b8e1f0 100644 --- a/packages/fhir-qb/index.test.js +++ b/packages/fhir-qb/index.test.js @@ -4641,7 +4641,7 @@ describe('Mongo Tests', () => { includeArchived, }); const expectedResult = [ - { $match: { $and: [{ $or: [{ foo: { $exists: true } }] }] } }, + { $match: { $and: [{ $or: [{ foo: { $exists: false } }] }] } }, { $match: { 'meta._isArchived': false } }, { $facet: { @@ -4678,7 +4678,7 @@ describe('Mongo Tests', () => { includeArchived, }); const expectedResult = [ - { $match: { $and: [{ $or: [{ foo: { $exists: false } }] }] } }, + { $match: { $and: [{ $or: [{ foo: { $exists: true } }] }] } }, { $match: { 'meta._isArchived': false } }, { $facet: {