When the user calls insert method from the client, it is executed twice. At first, I suspected user called it once on client and it executed twice on server(low internet connection) but after I make some adjustments to DateTime by replacing hour/minute/second/millisecond with the current time before insert, the two duplicated data on Database is different by milliseconds. If it is only called once on client and executed twice on server the DateTime(reqDate, refDate)
of the two records should be the same.
And here is my function to replace DateTime with the current time:
const wrapCurrentTime = (date) => {
date = moment(date)
const currentDate = moment()
date.hour(currentDate.hour())
date.minute(currentDate.minute())
date.second(currentDate.second())
date.millisecond(currentDate.millisecond())
return date
}
Client method:
submit() {
this.loading = true
const input= this.form
input.refDate = wrapCurrentTime(
moment(input.refDate, 'DD/MM/YYYY').toDate()
)
input.reqDate = wrapCurrentTime(
moment(input.reqDate, 'DD/MM/YYYY').toDate()
)
Meteor.apply('insertData', [input], { noRetry: true }, (error) => {
if (error) {
Notify.error({ message: error })
this.loading = false
return
}
Msg.success()
this.reset()
this.loading = false
})
}
It didn’t happen that often and I haven’t found the real cause of this issue, Is there a way to prevent this?