{"record":{"id":"e491a1a13a1bcafc","repo":"Automattic/mongoose","slug":"cannot-create-use-schema-for-property-path-be","errorCode":null,"errorMessage":"Cannot create use schema for property \"${path}\" because the schema has the timeseries option enabled.","messagePattern":"Cannot create use schema for property \"(.+?)\" because the schema has the timeseries option enabled\\.","errorType":"exception","errorClass":"InvalidSchemaOptionError","httpStatus":null,"severity":"error","filePath":"lib/schema/subdocument.js","lineNumber":41,"sourceCode":"\nlet SubdocumentType;\n\nmodule.exports = SchemaSubdocument;\n\n/**\n * Single nested subdocument SchemaType constructor.\n *\n * @param {Schema} schema\n * @param {string} path\n * @param {object} options\n * @param {Schema} parentSchema\n * @inherits SchemaType\n * @api public\n */\n\nfunction SchemaSubdocument(schema, path, options, parentSchema) {\n  if (schema.options.timeseries) {\n    throw new InvalidSchemaOptionError(path, 'timeseries');\n  }\n  const schemaTypeIdOption = SchemaSubdocument.defaultOptions?._id;\n  if (schemaTypeIdOption != null) {\n    options = options || {};\n    options._id = schemaTypeIdOption;\n  }\n\n  schema = handleIdOption(schema, options);\n\n  this.Constructor = _createConstructor(schema, null, options);\n  this.Constructor.path = path;\n  this.Constructor.prototype.$basePath = path;\n  this.schema = schema;\n  this.$isSingleNested = true;\n  this.base = schema.base;\n  SchemaType.call(this, path, options, 'Embedded', parentSchema);\n}\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/schema/subdocument.js#L23-L59","documentation":"Timeseries collections are a collection-level MongoDB feature. Mongoose refuses to embed a schema declared with `{ timeseries: ... }` as a single nested subdocument and throws InvalidSchemaOptionError at schema build time (lib/schema/subdocument.js:41), because a time series cannot live inside another document.","triggerScenarios":"`new Schema({ metrics: new Schema({ t: Date, v: Number }, { timeseries: { timeField: 't', metaField: 'm', granularity: 'hours' } }) })` — any nested use of a timeseries schema.","commonSituations":"Refactoring a standalone timeseries model into a parent model; sharing one base schema between a timeseries collection and embedded subdocuments via utils.pick/clone that copy options.","solutions":["Remove the `timeseries` option from the embedded schema; declare the nested schema without it","Keep `timeseries` only on the top-level schema passed to `mongoose.model()`","If the series must scale independently, store it in its own timeseries collection/model and reference it from the parent"],"exampleFix":"// before\nconst tsSchema = new Schema({ t: Date, v: Number }, { timeseries: { timeField: 't' } });\nnew Schema({ metrics: tsSchema }); // throws\n\n// after\nconst PointSchema = new Schema({ t: Date, v: Number });\nnew Schema({ metrics: [PointSchema] }); // embed plain points\nmongoose.model('Measurement', tsSchema); // timeseries stays top-level","handlingStrategy":"validation","validationCode":"function assertEmbeddable(schema, path) {\n  if (schema.options?.timeseries) {\n    throw new Error(`cannot embed schema with timeseries option at ${path}`);\n  }\n}","typeGuard":"const isEmbeddableSchema = schema => !schema?.options?.timeseries;","tryCatchPattern":null,"preventionTips":["Keep timeseries schemas in dedicated model files that are never imported for embedding","When cloning schemas, explicitly delete the timeseries option for the embedded copy","Add a startup assertion over embedded schemas if configs are data-driven"],"tags":["mongoose","schema","timeseries","mongodb","subdocument"],"backgroundTag":"invalid-schema-option","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}