{"record":{"id":"297ec4b548ede037","repo":"mongodb/node-mongodb-native","slug":"a-query-document-must-be-specified-for-query","errorCode":null,"errorMessage":"A query document must be specified for query","messagePattern":"A query document must be specified for query","errorType":"exception","errorClass":"MongoRuntimeError","httpStatus":null,"severity":"warning","filePath":"src/cmap/commands.ts","lineNumber":98,"sourceCode":"  oplogReplay: boolean;\n  noCursorTimeout: boolean;\n  awaitData: boolean;\n  exhaust: boolean;\n  partial: boolean;\n  /** moreToCome is an OP_MSG only concept */\n  moreToCome = false;\n  databaseName: string;\n  query: Document;\n\n  constructor(databaseName: string, query: Document, options: OpQueryOptions) {\n    // Basic options needed to be passed in\n    // TODO(NODE-3483): Replace with MongoCommandError\n    const ns = `${databaseName}.$cmd`;\n    if (typeof databaseName !== 'string') {\n      throw new MongoRuntimeError('Database name must be a string for a query');\n    }\n    // TODO(NODE-3483): Replace with MongoCommandError\n    if (query == null) throw new MongoRuntimeError('A query document must be specified for query');\n\n    // Validate that we are not passing 0x00 in the collection name\n    if (ns.indexOf('\\x00') !== -1) {\n      // TODO(NODE-3483): Use MongoNamespace static method\n      throw new MongoRuntimeError('Namespace cannot contain a null character');\n    }\n\n    // Basic optionsa\n    this.databaseName = databaseName;\n    this.query = query;\n    this.ns = ns;\n\n    // Additional options\n    this.numberToSkip = options.numberToSkip || 0;\n    this.numberToReturn = options.numberToReturn || 0;\n    this.returnFieldSelector = options.returnFieldSelector || undefined;\n    this.requestId = options.requestId ?? OpQueryRequest.getRequestId();\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/mongodb/node-mongodb-native/blob/dce7939f86fb283e167ad709955abedb7bf23124/src/cmap/commands.ts#L80-L116","documentation":"Thrown as a MongoRuntimeError in the OpQueryRequest constructor when the query document is null or undefined. OpQueryRequest wraps the legacy OP_QUERY wire protocol message. Like [105], this is an internal invariant — the driver never intentionally builds a query with no body.","triggerScenarios":"Internal construction of OpQueryRequest with a null/undefined query argument. Not reachable via the public API; indicates an internal driver error or a malformed mock in tests.","commonSituations":"Driver bug, broken test fixture, or direct internal API misuse.","solutions":["File a driver bug report with the full stack trace","In tests, ensure a non-null query document is passed when constructing OpQueryRequest","Do not call the @internal OpQueryRequest constructor directly"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isNonNullQuery(q: unknown): q is Record<string, unknown> {\n  return q != null && typeof q === 'object';\n}","tryCatchPattern":null,"preventionTips":["Never pass null/undefined as a query document to internal wire-protocol classes","Treat hits as driver bugs and report them"],"tags":["wire-protocol","internal","op-query"],"backgroundTag":null,"analyzedSha":"dce7939f86fb283e167ad709955abedb7bf23124","analyzedAt":"2026-08-11T04:54:53.215Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}