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

153
Visualizações
How to use mongoose to filtered the deleted users?

Heyyy guys ,

I need a function that ,when you delete a user ,you and that user been deleled won't see each orther in their users list . I am not sure how can I make this happen .Could you please help me ?

Thank you so much in advance !

User schema :

const mongoose = require("mongoose");


const userSchema = new mongoose.Schema(
  {
   
    userName: {
      type: String,
    },

    deleteList: [{ type: mongoose.Types.ObjectId, ref: "User" }],
    beenDeletedList: [{ type: mongoose.Types.ObjectId, ref: "User" }],
  }

);



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

module.exports = UserInfo;

Get all filted users (I am not sure how can filter all the users been deleted and show the rest of the users) :

exports.getSortedUsers = async (req, res, next) => {
   const user = await User.findById(req.body._id);

}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can exclude an array of object from mongoose find with the $nor operator.

In your case, you can try something like this :

exports.getSortedUsers = async (req, res, next) => {
   const users = await User.find({ $nor: beenDeletedList });
}

With beenDeletedList is the list of users blocked (deleted) by you.

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