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

290
Views
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 answers
Answer question

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 Report

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 Report

0

Check the docs

Dates are inserted in format given below

{"myDate": {"$date": "2010-07-20T23:23:50Z"}}
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!