My tech stack is Nest JS with mongo DB atlas.
When I create a document, I want a field ‘dateAdded’ parameter to be set with the value of current time by default. And for that I am not passing in the time parameter but defined it to be a default value with ‘new Date()’ in schema.
In Atlas this operation is always creating a constant time string to be created. Irrespective of when the document is created.
How to solve this ?
This is the schema for my conversations collections
@Schema({ collection: 'conversations', discriminatorKey: 'conversationType' })
export class Conversation {
@Prop({
type: String,
required: true,
enum: [GhlConversation.name, PodiumConversation.name],
})
conversationType: string;
@Prop({
type: String,
required: true,
default: new Date().toISOString(),
})
dateAdded: string;
@Prop({ required: false })
messageType?: string;
@Prop({ required: true })
direction: 'inbound' | 'outbound';
}