{"record":{"id":"9ba284ccae67f1ac","repo":"Automattic/mongoose","slug":"aggregate-near-argument-must-have-a-near-pro","errorCode":null,"errorMessage":"Aggregate `near()` argument must have a `near` property","messagePattern":"Aggregate `near\\(\\)` argument must have a `near` property","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"warning","filePath":"lib/aggregate.js","lineNumber":413,"sourceCode":" *       spherical: true,\n *     });\n *\n * @see $geoNear https://www.mongodb.com/docs/manual/reference/aggregation/geoNear/\n * @method near\n * @memberOf Aggregate\n * @instance\n * @param {object} arg\n * @param {object|number[]} arg.near GeoJSON point or coordinates array\n * @return {Aggregate}\n * @api public\n */\n\nAggregate.prototype.near = function(arg) {\n  if (arg == null) {\n    throw new MongooseError('Aggregate `near()` must be called with non-nullish argument');\n  }\n  if (arg.near == null) {\n    throw new MongooseError('Aggregate `near()` argument must have a `near` property');\n  }\n  const coordinates = Array.isArray(arg.near) ? arg.near : arg.near.coordinates;\n  if (typeof arg.near === 'object' && (!Array.isArray(coordinates) || coordinates.length < 2 || coordinates.find(c => typeof c !== 'number'))) {\n    throw new MongooseError(`Aggregate \\`near()\\` argument has invalid coordinates, got \"${coordinates}\"`);\n  }\n\n  const op = {};\n  op.$geoNear = arg;\n  return this.append(op);\n};\n\n/*!\n * define methods\n */\n\n'group match skip limit out densify fill'.split(' ').forEach(function($operator) {\n  Aggregate.prototype[$operator] = function(arg) {\n    const op = {};","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/aggregate.js#L395-L431","documentation":"validateSync() runs schema validators synchronously and returns a ValidationError (or undefined), but it skips middleware (pre/post validate hooks) and async validators. Mongoose has deprecated it: the warning prints on every call, and the method will be removed in Mongoose 10 in favor of the async Document.prototype.validate().","triggerScenarios":"Calling doc.validateSync() or doc.validateSync(['email']) anywhere in application or test code; passing the options object form doc.validateSync({ pathsToSkip: ['name'] }) — each call prints the deprecation warning once (utils.warn).","commonSituations":"Long-lived codebases that predate async validate; tests that synchronously assert validation errors; upgrading Mongoose 7/8/9 where the warning appears in CI logs and fails strict log-scanning tests; code that relied on the returned ValidationError without handling promises.","solutions":["Replace with await doc.validate() and catch the rejected ValidationError: try { await doc.validate(); } catch (err) { /* err instanceof mongoose.Error.ValidationError */ }.","Port assertions in tests to async: await expect(doc.validate()).rejects.toThrow(mongoose.Error.ValidationError).","Note that validate() also runs middleware and async validators — review any behavior that silently differed under validateSync().","Do not wait for Mongoose 10: the method is removed there, so the migration is mandatory before upgrading."],"exampleFix":"// before\nconst err = doc.validateSync();\nif (err) console.log(err.message);\n\n// after\ntry {\n  await doc.validate();\n} catch (err) {\n  if (err instanceof mongoose.Error.ValidationError) console.log(err.message);\n}","handlingStrategy":"validation","validationCode":"// static check: grep for validateSync in CI\n// require('child_process').execSync(\"grep -rn 'validateSync(' src/ && exit 1 || exit 0\")","typeGuard":null,"tryCatchPattern":"// async replacement pattern that preserves the old control flow:\ntry {\n  await doc.validate();\n} catch (err) {\n  if (err instanceof mongoose.Error.ValidationError) {\n    // handle like the old validateSync() return value\n  } else throw err;\n}","preventionTips":["Add a CI grep/codeownes rule rejecting new validateSync() usage.","When upgrading Mongoose majors, run the deprecation list from the migration guide against your codebase.","Remember validate() also runs middleware and async validators — update test expectations."],"tags":["mongoose","deprecation","validation","document","mongoose-10"],"backgroundTag":"deprecated-api-call","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}