обновить поле в массиве в документе в MongoDB
это пример документа в базе данных:
title: "donation"
description: "this is a donation"
appliers:
0: object
Status: "Pending"
City: "Madrid"
Country: "Spain"
1: object
2: object
Я хотел бы изменить статус в объекте на принимается, когда кто-то щелкает, принимается в интерфейсе. Я написал следующий код, но статус в базе данных не меняется с ожидающего на принятый tho
application.py
@application.route('/reject_collaborator/<string:title>/<string:applier>', methods=['GET'])
def reject_collaborator(title, applier):
AnnouncementService.put_in_rejected(title, applier)
flash('you have rejected the donator offer', 'success')
return redirect(url_for('select_collaborators', title=title))
Services.py
@staticmethod
def put_in_rejected(title, applier):
AnnouncementRepository.put_in_rejected(title, applier)
announcement = AnnouncementRepository.find_by_title(title)
temp = Announcement(announcement['title'], announcement['quantity'],
announcement['enroll_deadline'], announcement['description'],
announcement['status'], announcement['appliers'],
announcement['collaborators'], announcement['rejected'],
announcement['email_creator'], announcement['hospital_name'],
announcement['address'], announcement['zip_code'], announcement['city'],
announcement['region'], announcement['country'])
return temp
Repositaories.py
@staticmethod
def put_in_rejected(title, applier):
db.announcement.update({'title': title, 'appliers': applier},
{'set': {'appliers.$.status': 'Rejected'}})