#mongodb #mongoose
Вопрос:
У меня есть документ ниже, и мне нужно найти первый адрес null и установить значение «123», например, запрос будет искать в первом объекте массива четвертьфиналов, если firstParticipant.address === null, если он устанавливает адрес в «123», если не проверяет, если secondParticipant.address === null для устанавливает адрес в «123», если он не находит нулевой адрес в первом объекте из массива четвертьфиналов, проверяет следующий и т. Д.
{
"data": {
"createTournament": {
"rounds": {
"quarterFinals": [{
"id": "9fb6f9ca-c06a-4972-b140-0f2425a90707",
"arena": "",
"firstParticipant": {
"address": null,
"battlesWon": 0
},
"secondParticipant": {
"address": null,
"battlesWon": 0
}
},
{
"id": "9fb6f9ca-c06a-4972-b140-0f2425a90708",
"arena": "",
"firstParticipant": {
"address": null,
"battlesWon": 0
},
"secondParticipant": {
"address": null,
"battlesWon": 0
}
},
{
"id": "9fb6f9ca-c06a-4972-b140-0f2425a90709",
"arena": "",
"firstParticipant": {
"address": null,
"battlesWon": 0
},
"secondParticipant": {
"address": null,
"battlesWon": 0
}
}
]
}
}
}
}
Ожидаемый:
{
"data": {
"createTournament": {
"rounds": {
"quarterFinals": [{
"id": "9fb6f9ca-c06a-4972-b140-0f2425a90707",
"arena": "",
"firstParticipant": {
"address": '456',
"battlesWon": 0
},
"secondParticipant": {
"address": '999',
"battlesWon": 0
}
},
{
"id": "9fb6f9ca-c06a-4972-b140-0f2425a90708",
"arena": "",
"firstParticipant": {
"address": '444',
"battlesWon": 0
},
"secondParticipant": {
"address": null, // expected this address to be updated to '123'
"battlesWon": 0
}
},
{
"id": "9fb6f9ca-c06a-4972-b140-0f2425a90709",
"arena": "",
"firstParticipant": {
"address": null,
"battlesWon": 0
},
"secondParticipant": {
"address": null,
"battlesWon": 0
}
}
]
}
}
}
}
Комментарии:
1. Но ваши входные данные содержат все
null
адреса. Итак, какова логика первого объекта вывода?