diff --git a/metrik/targets/mongo.py b/metrik/targets/mongo.py index f941291..d6f18a1 100644 --- a/metrik/targets/mongo.py +++ b/metrik/targets/mongo.py @@ -38,8 +38,7 @@ class MongoTarget(Target): # Because MongoDB isn't microsecond-accurate, we need to set the # microseconds to 0 to ensure consistency present_deref = present if present is not None else datetime.now() - present_deref.replace(microsecond=0) - id_dict['_created_at'] = present_deref + id_dict['_created_at'] = present_deref.replace(microsecond=0) with self.get_db() as db: return db[self.collection].insert_one(id_dict).inserted_id diff --git a/test/targets/test_mongo_target.py b/test/targets/test_mongo_target.py index 9814147..693f6ed 100644 --- a/test/targets/test_mongo_target.py +++ b/test/targets/test_mongo_target.py @@ -54,8 +54,8 @@ class MongoTargetTest(MongoTest): r = t.retrieve() self.assertGreaterEqual(present, r['_created_at']) - one_second_past = present - timedelta(seconds=1) + second_prior = (present - timedelta(seconds=1)).replace(microsecond=0) t = MongoTarget('test_collection', 1235) - t.persist({}, present=one_second_past) + t.persist({}, present=second_prior) r = t.retrieve() - self.assertEqual(one_second_past, r['_created_at']) \ No newline at end of file + self.assertEqual(second_prior, r['_created_at']) \ No newline at end of file