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

173
Views
error when use Moment.js not accept to save in DB

when I try to use Moment.js in server code and do save action I get this error are there any solution or any alternative to change Date format

{
      stringValue: '"March 15th 2022, 2:28:00 am"',
      messageFormat: undefined,
      kind: 'date',
      value: 'March 15th 2022, 2:28:00 am',
      path: 'transactionTime',
      reason: AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:
        assert.ok(false)
        generatedMessage: true,
        code: 'ERR_ASSERTION',
        actual: false,
        expected: true,
        operator: '=='
      },
      valueType: 'string'
    }
  },
  _message: 'transaction validation failed'
}

Schema

var moment = require('moment');

const Schema = new mongoose.Schema({
    transactionTime: {
        type: Date,
        default: moment().format('MMMM Do YYYY, h:mm:ss a'),
    },
    ...
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I must let the type save in DB as Date and in default: Date.now() or if I use moment in Server code default: () => moment().toDate() then change the format after getting the value from DB like this

moment(transaction.transactionTime).format('MMMM Do YYYY, h:mm:ss a')
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!