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

171
Views
mongoose get collections that not includes certain item in sub document

this is my schema

const CourseSchema = new mongoose.Schema({
    title: {
    },
    cost: {
    },
    students: [
        {
            _id: ObjectId,
            fullName: String,
            email: String
        }
    ]
});

I have student John Doe with objectId: "something" , in mongoose how can I get courses that not include john doe? in simple words show him courses that he doesn't buy.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can simply use the $ne operator to do this:

db.collection.find({
  "students._id": {
    $ne: "id123"
  }
})

I've created an example for you on mongoplayground: https://mongoplayground.net/p/t9AyVVT9mAX

over 4 years ago · Santiago Trujillo 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!