{"record":{"id":"ff044195590366f3","repo":"Automattic/mongoose","slug":"cannot-set-hydratedpopulateddocs-option-to-false","errorCode":null,"errorMessage":"Cannot set `hydratedPopulatedDocs` option to false if `virtuals` option is truthy because `virtuals: true` also sets populated virtuals","messagePattern":"Cannot set `hydratedPopulatedDocs` option to false if `virtuals` option is truthy because `virtuals: true` also sets populated virtuals","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/model.js","lineNumber":4022,"sourceCode":" *     // hydrate previous data into a Mongoose document\n *     const mongooseCandy = Candy.hydrate({ _id: '54108337212ffb6d459f854c', type: 'jelly bean' });\n *\n * @param {object} obj\n * @param {object|string|string[]} [projection] optional projection containing which fields should be selected for this document\n * @param {object} [options] optional options\n * @param {boolean} [options.setters=false] if true, apply schema setters when hydrating\n * @param {boolean} [options.hydratedPopulatedDocs=false] if true, populates the docs if passing pre-populated data\n * @param {boolean} [options.virtuals=false] if true, sets any virtuals present on `obj`\n * @param {boolean|'throw'} [options.strict=false] configure strict mode for the hydrated document. In particular, if strict is false, fields not in the schema won't be stripped out; if strict is 'throw', `hydrate()` will throw an error if there are any fields that are not in the schema. Defaults to true (silently strip out fields not in the schema).\n * @return {Document} document instance\n * @api public\n */\n\nModel.hydrate = function hydrate(obj, projection, options) {\n  _checkContext(this, 'hydrate');\n\n  if (options?.virtuals && options?.hydratedPopulatedDocs === false) {\n    throw new MongooseError('Cannot set `hydratedPopulatedDocs` option to false if `virtuals` option is truthy because `virtuals: true` also sets populated virtuals');\n  }\n\n  if (projection != null) {\n    if (obj?.$__ != null) {\n      obj = obj.toObject(internalToObjectOptions);\n    }\n    projection = parseProjection(projection);\n    obj = applyProjection(obj, projection);\n  }\n  const document = require('./queryHelpers').createModel(this, obj, projection, projection, options);\n  document.$init(obj, options);\n  return document;\n};\n\n/**\n * Same as `updateOne()`, except MongoDB will update _all_ documents that match\n * `filter` (as opposed to just the first one) regardless of the value of\n * the `multi` option.","sourceCodeStart":4004,"sourceCodeEnd":4040,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/model.js#L4004-L4040","documentation":"Error \"Cannot set `hydratedPopulatedDocs` option to false if `virtuals` option is truthy because `virtuals: true` also sets populated virtuals\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/model.js:4022 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}