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

114
Views
How to Change the Format of current Date when storing it in mongoDB database

In the schema of mongoDB, I am trying to store current date using date.now(), but it is storing date in UTC format. How can I change the date format in local date?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

MongoDB stores dates in BSON Date type, UTC timestamp with 64-bit integer internally. What you want is store dates as local date formatting, just store them already formatted String, not Date. What you want is to see date values as local time, consider using $dateToString aggregation expression.

For example:

db.getCollection('users').aggregate([
  {
    $project: {
      createdAt: { $dateToString: { date: '$createdAt', timezone: 'Asia/Seoul' } }
    }
  }
])

//    { "_id": ..., "createdAt" : ISODate("2020-12-02T04:52:02.237Z") }
// -> { "_id": ..., "createdAt": "2020-12-02T13:52:02.237Z" }
about 4 years ago · Juan Pablo Isaza 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!