{"record":{"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":"warning","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/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/commands.ts#L519-L555","documentation":"Thrown as a MongoInvalidArgumentError in the OpMsgRequest constructor when the command document is null or undefined. OpMsgRequest is the modern (MongoDB 3.6+) OP_MSG wire protocol request. This is an internal invariant — the driver never intentionally builds an empty command.","triggerScenarios":"Internal construction of OpMsgRequest with a null/undefined command. Not reachable from the public API; would only occur from a driver bug, a faulty operation implementation, or a broken test mock.","commonSituations":"Driver bug, a custom operation subclass that returns null from its command builder, or test code that directly instantiates OpMsgRequest without a command.","solutions":["Report a driver bug with the stack trace if hit in production","In custom operation code, ensure the command document is always a non-null object","Avoid directly constructing the @internal OpMsgRequest class"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isNonNullCommand(cmd: unknown): cmd is Record<string, unknown> {\n  return cmd != null && typeof cmd === 'object';\n}","tryCatchPattern":null,"preventionTips":["Do not construct the internal OpMsgRequest with a null command","Report occurrences as driver bugs with a stack trace"],"tags":["wire-protocol","internal","op-msg"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}