I recently got the opportunity to attend MongoDB Event organized by MUG Chandigarh and in the event all participants got engaged with this squid games challenge and we enjoyed it so much. Here are some questions which I answered in the event -

1.Find Active Players: Retrieve all players who are still active in the game.
Ans — db.players.find({ status: “active” });

2.Count Number of Players: Count the total number of players.
Ans - db.players.countDocuments({});

3.Find Eliminations in Game No. 3: Find all eliminations in G003.
Ans - db.eliminations.find({ game_id: “G003” });

4.Players in Specific Age Range: Find players who are between 25 and 35 years old.
Ans - db.players.find({ age: { $gte: 25, $lte: 35 } });

5.Find Games With Difficulty Above 7: Find games with difficulty greater than 7.

Ans - db.games.find({ difficulty: { $gt: 7 } });

6.Find Most Common Elimination Reason: Group by reason and count the number of times each reason appears, sorting by frequency.

Ans - db.eliminations.aggregate([
{ $group: { _id: “$reason”, count: { $sum: 1 } } },
{ $sort: { count: -1 } }
]);

7.Top 5 Players with the Highest Debt Find the top 5 players based on the amount of debt they owe.

Ans - db.players.find().sort({ debt: -1 }).limit(5);

8.Players with odd age

Ans - db.players.find({ age: { $mod: [2, 1] } });

9.Game with Maximum Contribution towards Prize Pool

Ans - db.prize_pool.aggregate([
{ $group: { _id: “$game_id”, total_pool: { $sum: “$current_pool” } } },
{ $sort: { total_pool: -1 } },
{ $limit: 1 }
]);

10.Player with Maximum Debt in each Age Group

Ans - db.players.aggregate([
{ $group: { _id: “$age”, maxDebtPlayer: { $first: “$$ROOT” }, maxDebt: { $max: “$debt” } } },
{ $sort: { _id: 1 } }
]);

1 Like