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

117
Views
Mongoose Schema cannot be identified by code
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//broken schema
var coursesSchema = new Schema({
    college: {
        type: String,
        required: true
    },
    units: {
        type: Number,
        required: true
    },
    course_code: {
        type: String,
        required: true
    },
    course_name: {
        type: String,
        required: true
    },
    class_number: {
        type: String,
        required: true
    },
    section: {
        type: String,
        required: true
    },
    class_day: {
        type: String,
        required: true
    },
    time_start: {
        type: String,
        required: true
    },
    time_end: {
        type: String,
        required: true
    },
    faculty: {
        type: String,
        required: true
    }
});


module.exports = mongoose.model('Courses', coursesSchema);

//working schema
var mongoose = require('mongoose');
var Schema = mongoose.Schema;


var loaSchema = new Schema({
    process_name: {
        type: String,
        required: true
    },
   process_details: {
       type: String,
       required: true
    },
    process_deadline: {
        type: String,
        required: true
    },
});


module.exports = mongoose.model('LOA', loaSchema);

I have this schema which I export into index.js file. This schema works in other parts of the code except in index.js. When I query Courses schema, it returns model.find() is not a function. When I try creating a new Courses object it says Constructor is not a schema. I have other schemas that work fine inside index.js and I get to query them, but this schema is an exception.

Does anyone know the reason behind this?

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

0

index.js is the special file and actually it's root of your module, it's better separate the schema from that to prevent from bugs

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!