{"id":"ce20f7a87ba8c2cd","repo":"mongodb/node-mongodb-native","slug":"query-document-must-be-specified-for-query","errorCode":null,"errorMessage":"Query document must be specified for query","messagePattern":"Query document must be specified for query","errorType":"exception","errorClass":"MongoInvalidArgumentError","httpStatus":null,"severity":"error","filePath":"src/cmap/commands.ts","lineNumber":537,"sourceCode":"\n/** @internal */\nexport class OpMsgRequest {\n  requestId: number;\n  serializeFunctions: boolean;\n  ignoreUndefined: boolean;\n  checkKeys: boolean;\n  maxBsonSize: number;\n  checksumPresent: boolean;\n  moreToCome: boolean;\n  exhaustAllowed: boolean;\n  databaseName: string;\n  command: Document;\n  options: OpQueryOptions;\n\n  constructor(databaseName: string, command: Document, options: OpQueryOptions) {\n    // Basic options needed to be passed in\n    if (command == null)\n      throw new MongoInvalidArgumentError('Query document must be specified for query');\n\n    // Basic optionsa\n    this.databaseName = databaseName;\n    this.command = command;\n    this.command.$db = databaseName;\n\n    // Ensure empty options\n    this.options = options ?? {};\n\n    // Additional options\n    this.requestId = options.requestId ? options.requestId : OpMsgRequest.getRequestId();\n\n    // Serialization option\n    this.serializeFunctions =\n      typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;\n    this.ignoreUndefined =\n      typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : false;\n    this.checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/3366c21a6311e02f1be91da982f9b93d3cce99a0/src/cmap/commands.ts#L519-L555","documentation":"Thrown by the OpMsgRequest constructor (commands.ts:537) as a MongoInvalidArgumentError when the command document is null or undefined. OP_MSG is the modern wire protocol message; it requires a command body to serialize. Like errors 95/96 this guards an internal invariant - the public operation layer always supplies a command document.","triggerScenarios":"Internal code calling new OpMsgRequest(db, null, options) or new OpMsgRequest(db, undefined, options). Reachable only via driver internals, custom wire-protocol code, or a defect where a command builder returned null.","commonSituations":"Driver bug in a custom operation whose buildCommand() returned undefined; extension code that bypassed the standard Operation infrastructure.","solutions":["Report as a driver bug with the operation and driver version","Use the public Collection/Db APIs; do not construct OpMsgRequest manually","If writing a custom Operation, ensure buildCommand() always returns a Document"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await client.connect();\n} catch (e) {\n  if (e instanceof MongoInvalidArgumentError && /Query document must be specified/i.test(e.message)) {\n    // internal bug - report to driver maintainers\n  }\n  throw e;\n}","preventionTips":["Use the public Collection/Db APIs; never construct OpMsgRequest manually","Ensure custom Operation subclasses return a Document from buildCommand()","Report internal invariant violations with a repro"],"tags":["wire-protocol","internal","op-msg","validation"],"analyzedSha":"3366c21a6311e02f1be91da982f9b93d3cce99a0","analyzedAt":"2026-08-04T13:40:15.335Z","schemaVersion":2}