skip to Main Content

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

2

Answers


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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search