From 554b4e89465b69941fff26733189ffd1ba5e4cd6 Mon Sep 17 00:00:00 2001 From: dev2 Date: Tue, 13 Aug 2024 11:45:49 +0000 Subject: [PATCH] s1 --- src/routes/api/getGameScore.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/routes/api/getGameScore.js b/src/routes/api/getGameScore.js index 27abc68..c96a1e5 100644 --- a/src/routes/api/getGameScore.js +++ b/src/routes/api/getGameScore.js @@ -14,14 +14,27 @@ async function main() { const collection = database.collection('gameData'); // Replace with your collection name // Find a single document - const user = await collection.findOne({ userId: 'dsfdfgffgfgeg' }); + // const user = await collection.findOne({ userId: 'dsfdfgffgfgeg' }); + + const { userId, gameName, gameID } = req.body; + const gameData = await collection.findOne({ + userId: userId, + gameName: gameName, + gameID: gameID + }); + + if (gameData) { + res.json({gameData}); + } else { + res.status(404).json({ message: 'Game data not found' }); + } // Output the result - if (user) { - console.log('User found:', user); - } else { - console.log('No user found with the username "john_doe"'); - } + // if (user) { + // console.log('User found:', user); + // } else { + // console.log('No user found with the username "john_doe"'); + // } } catch (error) { console.error('Error connecting to MongoDB or performing query:', error); } finally {