Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
Mongoose Error: Schema is not constructor

Here my Schema file is given below

const mongoose = require("mongoose");

const ProblemSchema = new mongoose.Schema(
  {
    slug: {
      type: String,
      required: true,
      unique: true,
    },
    title: {
      type: String,
      required: true,
    },
    desc: { type: String },
    input: { type: String, required: true },
    output: { type: String, required: true },
    constraints: { type: String },
    statement: { type: String, required: true },
    testcase: [
      {
        input: { type: String },
        output: { type: String },
        sample: { type: Boolean },
        explanation: { type: String },
      },
    ],
  },
  { timestamps: true }
);

module.exports = mongoose.model("Problem", ProblemSchema);

When I save data using :

const Problem = require("./models/Problem");
const newData = new Problem(data)
await newData.save()

I get the "Problem is not a constructor" error. How do I solve this issue? Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Please import your model like this.

const Problem = require("./yourschema_file_path");

Not like this.

const { Problem } = require("./yourschema_file_path");

you dont have to destructure while import.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!