Am planning on using Mongo ObjectIDs to compare Timestamps i.e. :
$fourteenDaysAgo = time() - (14 * 86400);
$lookFor = array(
'_id' => $user
);
$updateFields = array(
'$pull' => array(
'Rewards' => array(
'_id' => array(
'$lt' => new MongoId(dechex($fourteenDaysAgo).'0000000000000000')
)
),
),
);
$returnFields = array(
'_id' => 1,
);
$userData = $db->users->findAndModify($lookFor, $updateFields, $returnFields);
The thing that irks me is this specifically
new MongoId(dechex($fourteenDaysAgo).'0000000000000000')
This has an uneasy, "hackish", feel about it compared to other libraries C# or Py where there's simply something like:
ObjectId.from_datetime( fourteen_days_ago )
I've been looking at the docs, but can't seem to find the equivalent for PHP... does it not exist? Is there a better way? I.e. Something that won't make me go "wtf was i doing here?" when i eventually revisit this script N months later?