Skip to content

Getting error about unsupported SchemaType using .toJSONSchema({ useBsonType: true }) #15489

@WojakGra

Description

@WojakGra

Prerequisites

  • I have written a descriptive issue title

Mongoose version

8.16.0

Node.js version

20.19.0

MongoDB version

8.0.6

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Ubuntu 22.04.5 LTS

Issue

Hi, i wanted to make a exporter that will allow me to create Diagram in PlantUML but in this case one model is giving me an error Converting unsupported SchemaType to JSON Schema: Mixed.

Here below is code for this model (changed variables for privacy):

import mongoose from 'mongoose'

const xFields = {
  procent: { type: Number, default: 0, min: 0, max: 100 },
  offset: { type: Number, default: 0 },
  cumulated: { type: Number, default: 0 },
}

const xSchema = new mongoose.Schema(
  {
    X: xFields, 
    XX: xFields, 
    XXX: xFields, 
    XXXX: xFields, 
    XXXXX: xFields, 
    XXXXXX: xFields, 
  },
  { _id: false },
)

const yFields = {
  start: { type: Number, default: 0 },
  end: { type: Number, default: 0 },
  duration: { type: Number, default: 0 },
  value: { type: Number, default: 0 },
  week: { type: Object, default: {} },
}

const ySchema = new mongoose.Schema(
  {
    Y: yFields,
    YY: yFields,
    YYY: yFields,
    YYYY: yFields,
    YYYYY: yFields,
    YYYYYY: yFields,
    YYYYYYY: yFields,
  },
  { _id: false },
)

const cFSchema = new mongoose.Schema(
  {
    revision: { type: mongoose.Schema.Types.ObjectId, ref: 'Revision', required: true },
    X: xSchema,
    Y: ySchema,
    Z: { type: Number, required: true, default: 0 },
  },
  { timestamps: true, optimisticConcurrency: true, collection: 'cf' },
)

cFSchema.index({ revision: 1 }, { unique: true })

const CF = mongoose.model('CF', cFSchema)

export default CF

Also is it possible to get a entity-relationship alike parameter of some sort

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions