Home > Back-end >  is there and function to convert Int64 value to date in mongodb
is there and function to convert Int64 value to date in mongodb

Time:05-10

Is there any method or function to convert int64 "637766000000000000" into date MongoDBenter image description here

CodePudding user response:

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

CodePudding user response:

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

  • Related