Aquí mi archivo de esquema se da a continuación
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);Cuando guardo datos usando:
const Problem = require("./models/Problem"); const newData = new Problem(data) await newData.save()Recibo el error "El problema no es un constructor". ¿Cómo soluciono este problema? Gracias por adelantado.
Importe su modelo así.
const Problema = require("./yourschema_file_path");
Así no.
const { Problema } = require("./yourschema_file_path");
no tienes que desestructurar mientras importas.