Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

427
Views
How to insert the timestamp in milliseconds as NumberLong in MongoDB using NodeJS

I new to nodejs and trying implement mongodb insert of current timestamp as milliseconds using nodejs its getting inserted as double value. Can anyone help me how to insert this as NumberLong value.

var data = {
        myId : uniqueId,
        Timestamp : Date.now(),   ---> This one is getting inserted as double.
        userData : applicationData
      }
    }

I also try to insert like this but its getting insert as String.

 var mongo=require('mongodb');
 var Long = mongo.Long;

 var data = {
        myId : uniqueId,
        Timestamp : Long.fromString((Date.now() + "")), ---> This one is getting inserted as String.
        userData : applicationData
      }
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This is because JavaScript Numbers are Always 64-bit Floating Point. You can use Mongo driver's Long ( https://mongodb.github.io/node-mongodb-native/api-bson-generated/long.html ) to get rid of this problem.

var Long = require('mongodb').Long;
var current_millies = new Date().getTime();

var data = {
 myId : uniqueId,
 timestamp : Long.fromNumber(current_millies),
 userData : applicationData
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!