Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

292
Vistas
Can't query date from MongoDB(Mlab) -- So simple but can't be solve

After weeks of effort, I'm still having trouble querying the date field movie_datetime which has the structure below from Mlab using NodeJS.

"movie_datetime": {
        "$date": "2017-01-03T16:00:00.000Z"
},
"session_id": 31268

enter image description here

I tried the following

db.mycollection.find({
  "movie_datetime" : {"gte" : { "$date" : "2013-10-01T00:00:00.000Z"}}
})

db.mycollection.find({
    "movie_datetime" : {"$gte": new Date("2013-10-01T00:00:00.000Z")}
})

db.mycollection.find({
    "movie_datetime" : {"$gte": Date("2013-10-01T00:00:00.000Z")}
})

db.mycollection.find({
    "movie_datetime" : {"$gte": ISODate("2013-10-01T00:00:00.000Z")}
})

Appreciate any help.

Current nodeJS Codes :

**Tried variations of single quotes and doubles quotes and omitting .toISOString

var dateTime = '{"movie_datetime":{"$gte" : "'+new Date("2017-01-03T16:00:00.000Z").toISOString()+'"}}';

var dateTimeJson =JSON.parse(dateTimeVar);

db.mycollection.find(dateTimeJson);


Result for print dateTime 
{"movie_datetime":{"$gte" : "2017-01-03T16:00:00.000Z"}}

Result for print dateTimeJson 
{ movie_datetime: { '$gte': '2017-01-03T16:00:00.000Z' } }

Node version 6.6.0

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

If you are using the mlab interface, it's actually like this:

{
    "createdAt": {
        "$gt": {
            "$date": "2017-11-08T20:05:45.866Z"
        }
    }
}
over 4 years ago · Santiago Trujillo Denunciar

0

I think this should do it.

db.myCollection.find({
  'movie_datetime.$date': {
    '$gte': new Date('2013-10-01T00:00:00.000Z')
  } 
});

edit - The picture you posted and the JSON you provided are different. For the picture it would be -

db.myCollection.find({
  'date.$date': {
    '$gte': new Date('2013-10-01T00:00:00.000Z')
  } 
});
over 4 years ago · Santiago Trujillo Denunciar

0

Check the docs

Dates are inserted in format given below

{"myDate": {"$date": "2010-07-20T23:23:50Z"}}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda