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

94
Vistas
i want to check if current user is following other user

i want to check if current user is following other use lets say check if user A is following user B.

User Model:-

const UserSchema = new Schema({
    email: {
        required: true,
        type: String,
        unique: true,
        lowercase: true,
        validate: (value) => {
            if (!validator.isEmail(value)) {
                throw new Error('Invalid email address.');
            }
        }
    },
    fullName: {
        required: true,
        type: String,
    },
    username: {
        required: true,
        type: String,
        unique: true,
        lowercase: true,
        minlength: 3,
    },
    password: {
        type: String,
        minlength: 8,
    },
    avatar: String,
    bio: {
        type: String,
        default: null,
        maxlength:300,
    },
    location: {
        type: String,
        default: 'Bangalore'
    },
    website: {
        type: String,
        default: null,
    },
    joindate: {
        type: Date,
        default: new Date()
    },
    isVerified:{
        type:Boolean,
        default:false,
    }

})

const UserModel = mongoose.model('User', UserSchema);
module.exports = UserModel;

Followings Model:-


const FollowingsSchema = new Schema({
    user: {
        ref: 'User',
        unique:true,
        type: Schema.Types.ObjectId,
    },
    followings: [{
        user: {
            type: Schema.Types.ObjectId,
            ref: 'User'
        }
    }]
})

const Followings = mongoose.model('Followings', FollowingsSchema);
module.exports = Followings;

Followers Model:-



const FollowersSchema = new Schema({
    user: {
        ref: 'User',
        unique:true,
        type: Schema.Types.ObjectId,
    },
    followers: [{
        user: {
            type: Schema.Types.ObjectId,
            ref: 'User'
        }
    }]
})

const Followers = mongoose.model('Followers', FollowersSchema);
module.exports = Followers;

currently i was able to achieve this by iterating through each follower and check if user exist in that user followers list. i want to achieve this with mongodb aggregation ,im new to mongob

about 4 years ago · Juan Pablo Isaza
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