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

202
Visualizações
MongoDb Date query with php doesn't work

I'm trying to get today's data from mongodb.

Here is a sample document:

{
   "_id": ObjectId("586a284a1f815b55608b456b"),
   "timestamp": "02/01/2017 03:45:36",
   "data": "29",
   "lat": "not available",
   "time": ISODate("2017-01-02T10:15:38.57Z") 
}

And here is the PHP code:

$query = array('time'=>array ('$gte'=>new mongoDate()));
$str = $collection->find($query);
foreach($str as $doc)
print_r($doc);

What am I doing wrong? I'm getting empty output.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You're using greater than and you have no datasets in the future, so there's nothing to be found.

I think that you're looking for $lte lesser than, which will give you datasets from the past.

over 4 years ago · Santiago Trujillo Relatório

0

You have a past date in the data and you are querying for the date greater than or equal to the current date i.e now or the future, which will be empty. You may need $lte (less than or equal to) which makes your query :

$query = array('time'=>array ('$lte'=>new mongoDate()));
over 4 years ago · Santiago Trujillo 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