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

180
Views
Mongodb time difference check

here's my data in a mongodb document

[
    {
        startTime: "08:00",
        endTime: "09:00",
        id: 1
    },
    {
        startTime: "08:10",
        endTime: "09:00",
        id: 2
    },
    {
        startTime: "10:00",
        endTime: "11:00",
        id: 3
    }
]

I need to find a way to get time overlapping elements using mongoose with node.js I trid using $dateFromString but no luck so far. for example item id 1 and 2 has time overlap

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

db.collection.aggregate([ { $match: {} }, { $setWindowFields: { partitionBy: "", sortBy: { startTime: 1 }, output: { previous_endTime: { $shift: { output: "$endTime", by: -1, default: "Not available" } } } } }, { $set: { c: { $cond: { if: { $and: [ { $gte: [ "$previous_endTime", "$endTime" ] }, { $gte: [ "$previous_endTime", "$startTime" ] } ] }, then: 0, else: 1 } } } }, { $setWindowFields: { partitionBy: "", sortBy: { startTime: 1 }, output: { c: { $sum: "$c", window: { documents: [ "unbounded", "current" ] } } } } }, { $group: { _id: "$c", c: { $sum: 1 }, id_List: { $push: "$id" } } }, { $match: { c: { $gt: 1 } } } ])

mongo playground

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!