Skip to content

Schema with timeseries and autoCreate: false does not create a timeseries collection #15986

@AnderbergE

Description

@AnderbergE

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

8.18.0

Node.js version

24

MongoDB server version

7.0.11

Typescript version (if applicable)

No response

Description

A schema that specifies both options timeseries and autoCreate: false does not create a timeseries collection.
This has not been fixed on the latest version. I have not tested older versions.
Please note that the documentation uses autoCreate: false: https://mongoosejs.com/docs/guide.html#timeseries
This may be related to this issue from 2022: #11916

Steps to Reproduce

This schema will create a type: 'collection' in MongoDB when the first document is inserted:

new Schema({
  meta: {
    devId: { type: String, required: true },
  },
  ts: { type: Date, required: true },
  count: { type: Number },
}, {
  timeseries: {
    timeField: 'ts',
    metaField: 'meta',
    granularity: 'minutes',
  },
  autoCreate: false,
})

This schema (without autoCreate) will create a type: 'timeseries' in MongoDB after connecting to db:

new Schema({
  meta: {
    devId: { type: String, required: true },
  },
  ts: { type: Date, required: true },
  count: { type: Number },
}, {
  timeseries: {
    timeField: 'ts',
    metaField: 'meta',
    granularity: 'minutes',
  },
})

Expected Behavior

When creating a model with schema that specifies timeseries, I expect that the collection in the MongoDB server is created as a timeseries type. If this cannot be solved, then I expect the documentation to write about it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions