简体   繁体   中英

is there and function to convert Int64 value to date in mongodb

Is there any method or function to convert int64 "637766000000000000" into date MongoDB 在此处输入图像描述

assuming that int64 is a timestamp, you could use toDate Mongo aggregation. Mongo toDate official docs

Check this

Aggregate

db.collection.aggregate([
  {
    $set: {
      date: {
        $toDate: {
          $divide: [
            { $subtract: [ "$date", 621355968000000000 ] },
            10000
          ]
        }
      }
    }
  }
])

mongoplayground


Update

db.collection.update({},
[
  {
    $set: {
      date: {
        $toDate: {
          $divide: [
            { $subtract: [ "$date", 621355968000000000 ] },
            10000
          ]
        }
      }
    }
  }
],
{
  multi: true
})

mongoplayground

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM