// Zapytanie wyszukujące dostępne pokoje o pojemności większej niż 2 osoby db.rooms.find( { status: "Dostępny", capacity: { $gt: 2 } } ) // Zapytanie wyszukujące rezerwacje z zameldowaniem w czerwcu 2023 db.reservations.find( { checkInDate: { $gte: new Date("2023-06-01"), $lt: new Date("2023-07-01") } } ) // Zapytanie grupujące - statystyki rezerwacji wg typu pokoju db.reservations.aggregate([ { $lookup: { from: "rooms", localField: "roomId", foreignField: "_id", as: "room" } }, { $unwind: "$room" }, { $group: { _id: "$room.type", averagePrice: { $avg: "$totalPrice" }, totalReservations: { $sum: 1 }, totalRevenue: { $sum: "$totalPrice" } } }, { $sort: { totalRevenue: -1 } }, { $project: { roomType: "$_id", averagePrice: { $round: ["$averagePrice", 2] }, totalReservations: 1, totalRevenue: 1, _id: 0 } } ]) // Zapytanie grupujące - analiza zamówień usług wg kategorii db.serviceOrders.aggregate([ { $lookup: { from: "services", localField: "serviceId", foreignField: "_id", as: "serviceDetails" } }, { $unwind: "$serviceDetails" }, { $match: { status: { $in: ["Potwierdzone", "Zrealizowane"] } } }, { $group: { _id: "$serviceDetails.category", totalOrders: { $sum: 1 }, totalRevenue: { $sum: "$totalPrice" }, averageQuantity: { $avg: "$quantity" } } }, { $sort: { totalOrders: -1 } }, { $limit: 5 }, { $project: { category: "$_id", totalOrders: 1, totalRevenue: { $round: ["$totalRevenue", 2] }, averageQuantity: { $round: ["$averageQuantity", 2] }, _id: 0 } } ]) // Zapytanie zliczające pokoje wg statusu dostępności db.rooms.countDocuments( { status: "Dostępny", pricePerNight: { $lt: 500 } } ) // Zapytanie o unikalne kraje pochodzenia gości db.guests.distinct( "address.country", { loyaltyPoints: { $gt: 50 } } )