{"record":{"id":"b89863b633958f76","repo":"meteor/meteor","slug":"unknown-operator-unprefixedkeys-0","errorCode":null,"errorMessage":"unknown operator: ${unprefixedKeys[0]}","messagePattern":"unknown operator: (.+?)","errorType":"exception","errorClass":"MiniMongoQueryError","httpStatus":null,"severity":"error","filePath":"packages/minimongo/common.js","lineNumber":1240,"sourceCode":"function populateDocumentWithKeyValue(document, key, value) {\n  if (value && Object.getPrototypeOf(value) === Object.prototype) {\n    populateDocumentWithObject(document, key, value);\n  } else if (!(value instanceof RegExp)) {\n    insertIntoDocument(document, key, value);\n  }\n}\n\n// Handles a key, value pair to put in the selector document\n// if the value is an object\nfunction populateDocumentWithObject(document, key, value) {\n  const keys = Object.keys(value);\n  const unprefixedKeys = keys.filter(op => op[0] !== '$');\n\n  if (unprefixedKeys.length > 0 || !keys.length) {\n    // Literal (possibly empty) object ( or empty object )\n    // Don't allow mixing '$'-prefixed with non-'$'-prefixed fields\n    if (keys.length !== unprefixedKeys.length) {\n      throw new MiniMongoQueryError(`unknown operator: ${unprefixedKeys[0]}`);\n    }\n\n    validateObject(value, key);\n    insertIntoDocument(document, key, value);\n  } else {\n    Object.keys(value).forEach(op => {\n      const object = value[op];\n\n      if (op === '$eq') {\n        populateDocumentWithKeyValue(document, key, object);\n      } else if (op === '$all') {\n        // every value for $all should be dealt with as separate $eq-s\n        object.forEach(element =>\n          populateDocumentWithKeyValue(document, key, element)\n        );\n      }\n    });\n  }","sourceCodeStart":1222,"sourceCodeEnd":1258,"githubUrl":"https://github.com/meteor/meteor/blob/5076d2f818d3cac01d0cf8312fa5b2332076a4fb/packages/minimongo/common.js#L1222-L1258","documentation":"During upsert document inference, populateDocumentWithObject treats an object as a literal sub-document only if it has unprefixed keys or is empty. If it mixes unprefixed (literal) keys with '$'-prefixed operator keys, the first unprefixed key is reported as 'unknown operator' because operators are not allowed to coexist with literal fields in the inferred insert document.","triggerScenarios":"An upsert equality clause whose value object mixes literal and operator keys, e.g. update({a: {b: 1, $gt: 0}}, ..., {upsert: true}). The upsert path tries to store 'a' as a literal {b:1,$gt:0} which is illegal.","commonSituations":"Building equality values by merging a literal object and an operator object into one, then upserting. Less common than 227 because this specifically concerns upsert insert-document inference.","solutions":["Do not mix literal and operator keys in a single equality value; split across fields or use $and.","Provide an explicit upsert insert document.","Restructure the selector so equality values are either fully literal or fully operator objects."],"exampleFix":"// before\ncoll.update({ a: { b: 1, $gt: 0 } }, { $set: { x: 1 } }, { upsert: true });\n// after\ncoll.update({ $and: [{ 'a.b': 1 }, { a: { $gt: 0 } }] }, { $set: { x: 1 } }, { upsert: true });","handlingStrategy":"validation","validationCode":"function isPureObjectValue(obj) {\n  if (!obj || typeof obj !== 'object') return true;\n  const keys = Object.keys(obj);\n  const ops = keys.filter(k => k[0] === '$');\n  const literals = keys.filter(k => k[0] !== '$');\n  return ops.length === 0 || literals.length === 0;\n}","typeGuard":"function isMixedKeyObject(obj) {\n  if (!obj || typeof obj !== 'object') return false;\n  const keys = Object.keys(obj);\n  return keys.some(k => k[0] === '$') && keys.some(k => k[0] !== '$');\n}","tryCatchPattern":null,"preventionTips":["Never merge a literal object and an operator object into one equality value for upsert.","Provide explicit upsert insert documents when value shapes are dynamic.","Run isPureObjectValue on equality values before upserting."],"tags":["minimongo","upsert","selector","operator","mixed-keys"],"backgroundTag":null,"analyzedSha":"5076d2f818d3cac01d0cf8312fa5b2332076a4fb","analyzedAt":"2026-08-13T03:27:40.142Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}