简体   繁体   English

是否有 function 将 Int64 值转换为 mongodb 中的日期

[英]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是否有任何方法或 function 将 int64 "637766000000000000" 转换为日期 MongoDB 在此处输入图像描述

assuming that int64 is a timestamp, you could use toDate Mongo aggregation.假设 int64 是时间戳,您可以使用toDate Mongo 聚合。 Mongo toDate official docs Mongo toDate 官方文档

Check this检查这个

Aggregate总计的

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

mongoplayground mongo游乐场


Update更新

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

mongoplayground mongo游乐场

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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