Error with Calculated Fields

I am currently trying to create a calculated field: where we divide the sum of total ad spend by sum of total views then multiply by 1000. However, this query currently leads to an “Unexpected “:” at character 50”

db.CreatorStats.aggregate([
  {
    $group: {
      _id: null,
      totalAdSpend: { $sum: "$Ad-Spend" },
      totalViews: { $sum: "$Views" }
    }
  },
  {
    $project: {
      _id: "null",
      result: {
        $multiply: [{ $divide: ["totalAdSpend", "totalViews"] }, 1000]
      }
    }
  }
]);

My database looks like below

The “Unexpected “:” is a syntax error, which is odd as the query looks well-formed to me.
One thing I can see is that you forgot to dollar-prefix the fields, you are diving, i.e:

{ $divide: ["$totalAdSpend", "$totalViews"] }
1 Like