我正在尝试检查是否已经存在具有当前日期的项目,如果没有,我将添加它。下面的代码没有提示任何错误,但它没有将任何内容保存到 MongoDB
if len(site.DaylyLog) != 0:
print len(site.DaylyLog)
print site.DaylyLog[-1]
current_date_daylylog = site.DaylyLog[-1]['aggregate_date']
else:
current_date_daylylog = ''
if current_date_daylylog == datetime.date.today():
#update document
print current_date_daylylog
print "calculating averages"
site.DaylyLog[-1].average_response_time = (site.DaylyLog[-1].average_response_time+record_uptime.response_time)/2
site.DaylyLog[-1].average_uptime = (site.DaylyLog[-1].average_uptime+100)/2
site.save()
else:
print current_date_daylylog
print "adding new uptime"
print site.url
aggregate_uptime = AggregatedUptime()
aggregate_uptime.average_response_time = record_uptime.response_time
aggregate_uptime.average_uptime = 100
aggregate_uptime.total_downtime = 0
aggregate_uptime.aggregate_date = datetime.date.today()
print aggregate_uptime.aggregate_date
print aggregate_uptime.average_response_time
site.DaylyLog.append(aggregate_uptime)
site.save()
print site.DaylyLog[-1].aggregate_date