Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

426
Visualizações
`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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda