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