// Query using the aggregation pipeline to calculate the total fine revenue
db.borrowedbooks.aggregate([
  {
    $group: {
      _id: null,
      "totalRevenue": { $sum: "$fine" }
    }
  }
]);
// 1. Clear out old borrowed records to avoid duplicate IDs
db.borrowedbooks.drop();

// 2. Insert records that actually include fine amounts
db.borrowedbooks.insertMany([
  { "borrowID": 901, "memberID": 501, "bookID": 101, "borrowDate": "2026-06-01", "returnDate": "2026-06-15", "fine": 25.50 },
  { "borrowID": 902, "memberID": 502, "bookID": 102, "borrowDate": "2026-06-10", "returnDate": "2026-06-28", "fine": 15.00 }
]);

// 3. Execute the assignment aggregation query
db.borrowedbooks.aggregate([
  {
    $group: {
      _id: null,
      "totalRevenue": { $sum: "$fine" }
    }
  }
]);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: