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

122
Views
Fetch a field value and compare it with values inside an array of sub documents in MongoDB

this is my mongoDB document, i want check if the date in sessionDate is present inside the array unavailableDates.

This is my schema

const adminSchema = new mongoose.Schema({
sessionDate:{
    type:Date
    
},
unavailableDates:{
   type: [Date]
},
 email:{
    type:String,
    required:true,
    min:6,
    max:255
},
password:{
    type:String,
    required:true,
    min:6,
    max:1024
},
});
 module.exports = mongoose.model('Admin',adminSchema);

This is my mongoose document

_id: objectId('6332d9846c4803d9ffc53bb0') 
"email":"someemail@mail.com"

 "password":"$2b$10$0ixZcynrlRhHQs14xJzPhO5Zn5scbWMrUFwbC/S6nrDI7qe9ZeJ0e"
unavailableDates: Array
0: 2022-09-08T18:30:00.000+00:00
1: 2022-10-09T18:30:00.000+00:00
2: 2021-12-31T18:30:00.000+00:00
3: 2022-01-01T18:30:00.000+00:00  
sessionDate: 2021-12-31T18:30:00.000+00:00
almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you want to check if at least one of unavailableDates array entries is same as sessionDate this is one option:

db.collection.aggregate([
{
 "$match": {
   "$expr": {
     "$in": [
        "$sessionDate",
        "$unavailableDates"
      ]
     }
   }
 }
])

playground

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