My Document retrieval process looks like this:
async findOne(id: string) {
return await this.gameModel.findById(id);
}
async update(id: string, updateGameDto: UpdateGameDto) {
const game = await this.findOne(id)
// This code snippet prints all keys as expected
for( const key in game){
console.log(key)
}
// ...
const keys = Object.keys(game) // [ '$__', '$isNew', '_doc' ]
return;
}
Why is Object.keys(game)
only returning those 3 keys? This limitation prevents me from accessing specific keys using the method below:
const specificKeyByValue = Object.keys(game).find(key => game[key] === "SomeValue")
I could resort to creating a function that retrieves the key with a for loop
like so;
const getKeyByValue = (obj, value) =>
{
for( const key in obj)
{
if(obj[key] === value) return key;
}
}
However, I would rather avoid creating additional functions if possible. Can anyone explain why this particular version of Object.Keys()
is not functioning correctly?