Whenever there is a trigger, I want to add a field to document “i.e” current timestamp in required format,(MM-DD-YY seconds) seconds will be number of seconds in that particular day.
I tried using Date() and Date.Now() and tried referring the documentation as wellDate but I didn’t got the expected output.
Do not worry about how your timestamp is stored in your data.
If you want to present it in a particular format do that at the application layer.
You may use $dateToParts to do than just before your application get the data.
You may also use the locale API supplied by your programming language of choice directly in your application. And to me it is better there than using $dateToParts. It is easier to scale data formatting (and user customization) at the application layer versus data access layer.
I want to add a field , business name concatenated timestamp (with above mentioned format) on insertion trigger.It’s a business use case where I need to represent the field in the expected format.
So I need to add field on an insertion itself in to collection.
just store the field as a Date which is supported in MongoDB and is most often the better thing to do when storing a date in the database. Your client-side application can be in charge of how it wants to convert a date into a string