Answer the question
In order to leave comments, you need to log in
How to find an object in an array in MongoDB?
Hello, I need to get a certain object from the array by the Y and X keys, now I'm doing it somehow crookedly, except for the fact that this code does not work at all:
async function findInArray(Y, X) {
let game = await Game.findById(какой-то ИД)
// allClick – это массив из объектов, по ключам Y и X ищу нужный мне объект
let player = game.allClick.find(k => k.Y == Y && k.X == X)
return player
}
_id: 1
...
...
allClick: [
0: {Y: 2, X: 5, player: 0xD34F}
1: {Y: 7, X: 3, player: squadbrodyaga}
2: ...
]
__v: 0
Answer the question
In order to leave comments, you need to log in
Based on your comment one might conclude that you should call the function as await findInArray(Y, X)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question