Trying to translate timestamp to ISO time on my device by aggregate

I have some data like time:

{
timeStamp:1630504773861
}

and I want to do this:
1st: read timeStamp into aggregate
2nd: translate timestamp into ISO time

db.orders.aggregate([
    {
      $group:{
        _id:null, "ISOtime": {$addToSet:new Date($timeStamp).toISOString()}}
    }
    ])

but it works failed :
ReferenceError: $timeStamp is not defined

HOW SHOW I WRITE THIS AGGREGATAION?

Hi @yang_xiaoyu, welcome to the community.

Try using $toDate operator.

db.orders.aggregate([
    { $group:{ _id:null, "ISOtime": {$addToSet: { $toDate: "$timeStamp" }}} }
    ])

Mahi

it works ,thanks a lot !

db.sf_license_config.aggregate([
{$group:{_id:null, “ISOdate”: {$addToSet: {$toDate: “$timestamp”}}}}
])
< { _id: null, ISOdate: [ 2021-09-02T01:02:20.670Z ] }

it’s batter:

db.sf_license_config.aggregate([
{$group:{_id:"$_id", “ISOdate”: {$addToSet: {$toDate: “$timestamp”}}}}
])

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.