diff --git a/managers/mongodb_manager.py b/managers/mongodb_manager.py index 2fe84dd..cafb5ce 100644 --- a/managers/mongodb_manager.py +++ b/managers/mongodb_manager.py @@ -123,7 +123,7 @@ class MongoDBArticleCache: 'url': article.get_url(), 'images': article.get_images(), 'modified_at': article.get_modified_at(), - 'expiresAt': expires_at, + #'expiresAt': expires_at, } # Preparar user_info @@ -197,14 +197,18 @@ class MongoDBArticleCache: 'notified_at': now, 'is_favorite': False, }] - new_article_data['createdAt'] = now - new_article_data['updatedAt'] = now + # Usar $setOnInsert para createdAt y updatedAt + # Solo se establecerán si el documento es nuevo (insert), no si ya existe (update) operations.append( UpdateOne( {'platform': platform, 'id': article_id}, { '$set': new_article_data, + '$setOnInsert': { + 'createdAt': now, + 'updatedAt': now + } }, upsert=True ) @@ -258,8 +262,7 @@ class MongoDBArticleCache: {'platform': platform, 'id': str(article_id)}, { '$set': { - 'user_info': user_info_list, - 'updatedAt': datetime.utcnow() + 'user_info': user_info_list } } )