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

162
Views
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 answers
Answer question

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 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!