I want to define a MongoDB partialFilterExpression which is based on the comparison of two document fields. Specifically, it is about comparing two date fields. The index should only be effective if one date (here processingTime) is larger than the other date (here creationTime).
I tried it the following way but that does not seem to work (because the document are not removend via the TTL index condition).
db.
getSiblingDB('foo').
getCollection('bar').
createIndex(
{ creationTime: 1 },
{
expireAfterSeconds: 60,
partialFilterExpression: {
processingTime: { $exists: true },
processingTime: {$gt: "$creationTime"}
}
}
);
I guess that $creationTime is not evaluated as a document field but only as simple text.
Is there a way to reach my goal?