Mongodb aggregate: convert date to another timezone
<p>I save my transaction with something like :</p>

<pre><code>{code: "A", total: 250000, timestamp: ISODate("2016-01-20T23:57:05.771Z")},
{code: "B", total: 300000, timestamp: ISODate("2016-01-20T05:57:05.771Z")}
</code></pre>

<p>each of transaction has <code>timestamp</code> field under UTC timezone in it. Since I live in Jakarta (UTC+7) timezone, I need to add 7 hours to my timestamp before aggregation. Here's my mongo syntax:</p>

<pre><code>db.transaction.aggregate(
[
 {
   $project:
     {
       year: { $year: "$timestamp" },
       month: { $month: "$timestamp" },
       day: { $dayOfMonth: "$timestamp" }
     }
 }
])
</code></pre>

<p>It returns:</p>

<pre><code>    {
        "_id" : ObjectId("56a01ed143f2fd071793d63b"),
        "year" : 2016,
        "month" : 1,
        "day" : 20
    },
    {
        "_id" : ObjectId("56a01ed143f2fd071793d63b"),
        "year" : 2016,
        "month" : 1,
        "day" : 20
    }
</code></pre>

<p>which is wrong since the first transaction (code <code>A</code>), is happened at 21st January, but since it was converted to UTC (-7 Hours), it became <code>ISODate("2016-01-20T23:57:05.771Z")</code></p>

<p>Note: I'm aware <a href="https://stackoverflow.com/questions/18852095/how-to-agregate-by-year-month-day-on-a-different-timezone">about the same problem over here</a>, here's what I've been tried so far:</p>

<pre><code>db.transaction.aggregate(
[
 {$project: {"timestamp": {$add: [7 * 60 * 60 * 1000]}}},
 {
   $project:
     {
       year: { $year: "$timestamp" },
       month: { $month: "$timestamp" },
       day: { $dayOfMonth: "$timestamp" }
     }
 }
])
</code></pre>

<p>but it returns <code>can't convert from BSON type NumberDouble to Date</code> error. 
Any suggestions?</p>