Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
MongoDB, Data between two Dates, records that match StartTime Irrespective of EndTime, records that match EndTime Irrespective of StartTime

For Example:

[
    {
        "title": "test1",
        "startDate": "2022-05-16T10:56:33.005Z",
        "endDate": "2022-05-16T13:56:33.005Z",
    },
    {
        "title": "test2",
        "startDate": "2022-05-11T00:00:00.000Z",
        "endDate": "2022-05-11T00:00:00.000Z",
    },
    {
        "title": "test3",
        "startDate": "2022-05-19T00:00:00.000Z",
        "endDate": "2022-05-19T00:00:00.000Z",
    },
    {
        "title": "test4",
        "startDate": "2022-05-16T12:00:33.005Z",
        "endDate": "2022-05-16T13:56:33.005Z",
    },
    {
        "title": "test5",
        "startDate": "2022-05-16T11:00:33.005Z",
        "endDate": "2022-05-16T15:56:33.005Z",
    },
    {
        "title": "test6",
        "startDate": "2022-05-16T14:50:33.005Z",
        "endDate": "2022-05-17T01:50:33.005Z",
    }
]

,

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As a result of my research, I found the answer

query = {
$or: [
    { // inbetween
    $and: [
            { startDate: { $gte: new Date(data.from_date)
                }
            },
            { endDate: { $lte: new Date(data.to_date)
                }
            },
        ]
    },
    { // 3 to 5 ----- 1 to 4 hours

    $and: [
            { startDate: { $lte: new Date(data.from_date)
                }
            },
            { endDate: { $gte: new Date(data.from_date)
                }
            },
        ]
    },
    { // 3 to 5 ---- 4 to 8 hours
    $and: [
            { startDate: { $lte: new Date(data.to_date)
                }
            },
            { endDate: { $gte: new Date(data.to_date)
                }
            },
        ]
    }
]

}

Answer: [ { "title": "test1", "startDate": "2022-05-16T10:56:33.005Z", "endDate": "2022-05-16T13:56:33.005Z", }, { "title": "test4", "startDate": "2022-05-16T12:00:33.005Z", "endDate": "2022-05-16T13:56:33.005Z", }, { "title": "test5", "startDate": "2022-05-16T11:00:33.005Z", "endDate": "2022-05-16T15:56:33.005Z", }, { "title": "test6", "startDate": "2022-05-16T14:50:33.005Z", "endDate": "2022-05-17T01:50:33.005Z", } ],

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda