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

435
Views
`User` is not a valid type at path `ref`

I couldn't find an error can anyone help me with this. I dont understand what the error here.

**Invalid schema configuration: User is not a valid type at path ref.

MatchList Schema

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const {ObjectId} = mongoose.Schema;

const match = new Schema({
    type: ObjectId,
    ref:'User'
},{
    timestamp:true
});
const matchList = new Schema({
    user:{
        type: ObjectId,
        ref:'User'
    },
    matches:[match]    
    },{
        timestamp:true
    });

const MatchList = mongoose.model('Match',matchList);

module.exports = MatchList;

UserSchema

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var UserSchema = new Schema({
    firstname:{
        type:String,
        required:true
    },
    lastname:{
        type:String,
        required:true
    },
    email:{
        type:String,
        required:true,
        unique:true
    },
    imgUrl:{
        type:String
    },
    age:{
        type:Number,
        required:true,
        min:16
    },
    gender:{
        type:String,
        required:true
    },
    place:{
        type:String,
    }
},{
    timestamp:true
});

const User = mongoose.model('User',UserSchema);
module.exports = User;
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Solution

Your UserSchema is totally fine. But, you made a mistake on your MatchList Schema code in line 5. Here is the solution:

MatchList Schema

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const { ObjectId } = mongoose.Schema

const match = new Schema({
    user: {   // <-- You didn't put variable name here before.
        type: ObjectId,
        ref: 'User'
    }
}, { timestamp: true });

const matchList = new Schema({
    user: {
        type: ObjectId,
        ref: 'User'
    },
    matches: [match]
}, {
    timestamp: true
});

const MatchList = mongoose.model('Match', matchList);

module.exports = MatchList;
over 4 years ago · Santiago Trujillo 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!