{"record":{"id":"452bd04c3bc1a227","repo":"Automattic/mongoose","slug":"cannot-create-use-schema-for-property-key-bec","errorCode":null,"errorMessage":"Cannot create use schema for property \"${key}\" 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/documentArray.js","lineNumber":44,"sourceCode":"\nlet MongooseDocumentArray;\nlet Subdocument;\n\n/**\n * SubdocsArray SchemaType constructor\n *\n * @param {string} key\n * @param {Schema} schema\n * @param {object} options\n * @param {object} schemaOptions\n * @param {Schema} parentSchema\n * @inherits SchemaArray\n * @api public\n */\n\nfunction SchemaDocumentArray(key, schema, options, schemaOptions, parentSchema) {\n  if (schema.options?.timeseries) {\n    throw new InvalidSchemaOptionError(key, 'timeseries');\n  }\n  const schemaTypeIdOption = SchemaDocumentArray.defaultOptions?._id;\n  if (schemaTypeIdOption != null) {\n    schemaOptions = schemaOptions || {};\n    schemaOptions._id = schemaTypeIdOption;\n  }\n\n  if (schemaOptions?._id != null) {\n    schema = handleIdOption(schema, schemaOptions);\n  } else if (options?._id != null) {\n    schema = handleIdOption(schema, options);\n  }\n\n  const Constructor = _createConstructor(schema, options);\n  Constructor.prototype.$basePath = key;\n  Constructor.path = key;\n\n  const $parentSchemaType = this;","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/schema/documentArray.js#L26-L62","documentation":"InvalidSchemaOptionError thrown when a DocumentArray (embedded subdocument array) is created from a schema carrying `{ timeseries: true }`. Timeseries is a collection-level MongoDB option that changes how the whole collection stores data; an embedded array lives inside parent documents and cannot be a timeseries, so Mongoose rejects the combination at schema-construction time instead of silently ignoring it.","triggerScenarios":"`new Schema({ readings: [new Schema({ t: Date, v: Number }, { timeseries: true })] })` — any subdocument-array element schema with the timeseries option set. Also building a DocumentArray schematype directly with such a schema.","commonSituations":"Copying a working standalone timeseries model's schema into another schema as an embedded array during refactors; merging shared schema definitions where one variant was used for a timeseries collection; following a timeseries tutorial and pasting options into the wrong place.","solutions":["Remove `timeseries: true` from the embedded schema — it only belongs on the top-level model's schema/collection options","If you need real time-series storage, keep it as a separate model on its own collection and reference it by ObjectId from the parent","If the option leaked in through a shared schema module, clone the schema and delete `schema.options.timeseries` before embedding","Add a unit test asserting your compiled schemas construct, so invalid options fail in CI, not at runtime"],"exampleFix":"// before\nconst readingSchema = new Schema({ t: Date, v: Number }, { timeseries: true });\nnew Schema({ readings: [readingSchema] });\n\n// after\nconst readingSchema = new Schema({ t: Date, v: Number });\nnew Schema({ readings: [readingSchema] });\n// and, if needed, a separate timeseries model:\n// db.model('Reading', readingSchema, 'readings'); + createCollection({ timeseries: ... })","handlingStrategy":"validation","validationCode":"function assertEmbeddable(subSchema, key) {\n  if (subSchema.options && subSchema.options.timeseries) {\n    throw new Error(`cannot embed schema ${key}: timeseries option must be removed`);\n  }\n}\nassertEmbeddable(readingSchema, 'readings');\nnew Schema({ readings: [readingSchema] });","typeGuard":null,"tryCatchPattern":"try { new Schema({ readings: [readingSchema] }); } catch (err) { if (err.name === 'InvalidSchemaOptionError' || /timeseries/.test(err.message)) { delete readingSchema.options.timeseries; } else throw err; }","preventionTips":["Keep timeseries models as standalone top-level schemas","Add schema-compilation smoke tests in CI so invalid options fail at build time","Audit shared schema modules for collection-level options before embedding"],"tags":["mongoose","schema","timeseries","embedded-document","invalid-option"],"backgroundTag":"invalid-schema-option","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}