Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

385
Vistas
mongoose population (refs) is not working

I have created two models where I am trying to ref one model to another but it's not working and I don't have any idea about it I used it exactly the same way as in the mongoose example but it is not helping, the only difference between my working and their example is I have two different files for both models and I am exporting them to use in another file

The example I took reference from Mongoose

First Model

const userModel = require('./userModel')
const {Schema} = mongoose

const tweet = new Schema({
    date: {
        type: Date,
        required: true,
    },
    msg:{
        type: String,
        maxlength:140,
        required:true
    },
    tweetid:{
        type: mongoose.Types.ObjectId
    }
})

const tweetSchema = new Schema({
    user: {
        type: Schema.Types.ObjectId,
        ref: 'userModel'
    },
    tweets: {
        type: [{tweet}],
        default: []
    }
})

const tweetModel = mongoose.model('tweet',tweetSchema)

module.exports = tweetModel

Second Model

const {Schema} = mongoose

const userSchema = new Schema({
    email: {
        type:String,
        required: true,
        unique: true,
        trim:true
    },
    password: {
        type:String,
        required: true,
        trim:true
    },
    follows: {
        type: [String],
        default: []
    }
})

const userModel = mongoose.model("User",userSchema) 

module.exports = userModel
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Your reference string should be equal to the model name that you have passed to mongoose.model:

const tweetSchema = new Schema({
    user: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    tweets: {
        type: [{tweet}],
        default: []
    }
})
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda