MongoDB Server Community: v4.2.7
Is it possible to define a collection where a date field will be included with every document insert?
Ie. if I insert { field1: "foo", field2: "bar" }
I want a created
field to be included: { field1: "foo", field2: "bar", created: Date(...) }
Is this possible?
Edit: For more details, I want to do this so I can create a TTL index on the created
field so documents are automatically pruned every x seconds. As I understand it, I need to manually insert the date field on each document insert. I would like to avoid this, if possible.