I am trying to use MongoDBs TTL feature and have 3 parts of a puzzle.
Part 1: According to the MongoDB docs it needs an ISODate object. This ISODate cannot be a string. An example is shown below:
db.something.createIndex({"someAgeOff": 1}, {"expireAfterSeconds": 60});
db.something.insertOne({"someAgeOff", new Date()});
db.something.find();
[{
_id: ObjectId("someId"),
someAgeOff: ISODate("2023-01-18T17:42:23:532Z");
}]
Part 2: I need to do the same thing as above, but in Spring. I believe we are supposed to use Instant to do this.
@Autowired
org.springframework.data.mongodb.core.ReactiveMongoTemplate template;
...
template.save(Something.newBuilder().ageOff(java.time.Instant.now()).build());
Part 3: I am using the netflix-dgs packages to write GraphQL and auto-generate the class files used in Spring. This means I cannot annotate the java class files w/o having to write some kind of script to do this every time the class files get regenerated/change. An example of a graphql file looks like below:
type Something {
ageOff: ???
}
I do not know what type to set for ageOff. If I use a string, then MongoDB will incorrectly store the value as a string and not an ISODate. If I use a Long, it stores it as a Long, etc. I don't mind making a custom Scalar but I have no idea how to make an 'ISODate' one.
Any thoughts/suggestions?
Thanks!