{"record":{"id":"80e502459206f5f8","repo":"meteor/meteor","slug":"argument-to-type-is-not-a-number-or-a-string","errorCode":null,"errorMessage":"argument to $type is not a number or a string","messagePattern":"argument to \\$type is not a number or a string","errorType":"exception","errorClass":"MiniMongoQueryError","httpStatus":null,"severity":"error","filePath":"packages/minimongo/common.js","lineNumber":126,"sourceCode":"          'javascriptWithScope': 15,\n          'int': 16,\n          'timestamp': 17,\n          'long': 18,\n          'decimal': 19,\n          'minKey': -1,\n          'maxKey': 127,\n        };\n        if (!hasOwn.call(operandAliasMap, operand)) {\n          throw new MiniMongoQueryError(`unknown string alias for $type: ${operand}`);\n        }\n        operand = operandAliasMap[operand];\n      } else if (typeof operand === 'number') {\n        if (operand === 0 || operand < -1\n          || (operand > 19 && operand !== 127)) {\n          throw new MiniMongoQueryError(`Invalid numerical $type code: ${operand}`);\n        }\n      } else {\n        throw new MiniMongoQueryError('argument to $type is not a number or a string');\n      }\n\n      return value => (\n        value !== undefined && LocalCollection._f._type(value) === operand\n      );\n    },\n  },\n  $bitsAllSet: {\n    compileElementSelector(operand) {\n      const mask = getOperandBitmask(operand, '$bitsAllSet');\n      return value => {\n        const bitmask = getValueBitmask(value, mask.length);\n        return bitmask && mask.every((byte, i) => (bitmask[i] & byte) === byte);\n      };\n    },\n  },\n  $bitsAnySet: {\n    compileElementSelector(operand) {","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/meteor/meteor/blob/5076d2f818d3cac01d0cf8312fa5b2332076a4fb/packages/minimongo/common.js#L108-L144","documentation":"Thrown by the $type operator when the operand is neither a string (alias) nor a number (BSON code). $type only accepts those two operand kinds; anything else (boolean, array, object, null, undefined) is rejected before any alias/code lookup.","triggerScenarios":"Using {field: {$type: true}}, {field: {$type: null}}, {field: {$type: [1]}}, or {field: {$type: {}}} in a minimongo query.","commonSituations":"Passing a boolean flag; passing null from an optional config; wrapping the code in an array; passing an object that was meant for a different operator.","solutions":["Provide a string alias or numeric code: {field: {$type: 'string'}}.","If the operand is optional, default it before building the selector.","Validate the operand is string|number before constructing the query."],"exampleFix":"// before\ncollection.find({ value: { $type: true } });\n// after\ncollection.find({ value: { $type: 'bool' } });","handlingStrategy":"type-guard","validationCode":"function typeSelector(operand) {\n  if (typeof operand !== 'string' && typeof operand !== 'number') {\n    throw new TypeError('$type operand must be string alias or number code');\n  }\n  return { $type: operand };\n}","typeGuard":"function isValidTypeOperand(op) {\n  return typeof op === 'string' || typeof op === 'number';\n}","tryCatchPattern":null,"preventionTips":["Only pass string aliases or numeric codes to $type.","Default optional operands before building the selector.","Validate operand type at the selector-builder boundary."],"tags":["minimongo","query","operator","type","validation","bson"],"backgroundTag":null,"analyzedSha":"5076d2f818d3cac01d0cf8312fa5b2332076a4fb","analyzedAt":"2026-08-13T03:27:40.142Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}