Below is the Schema file that I'm using:
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);
Whenever I try to save data with the following code:
const Problem = require("./models/Problem");
const newData = new Problem(data)
await newData.save()
I encounter the error message "Problem is not a constructor." How can I resolve this issue? Appreciate your help in advance.