Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert long value in mongo using node?

I need to insert Long value for an attribute in mongo.

  var sequences = this.db.collection('sequences');
  sequences.insert( {
      _id: "TEST_SEQ",
      value: 1
  }, done);

But this is inserting value as integer, how to make it Long?

like image 600
Karthik Chandraraj Avatar asked Sep 17 '25 23:09

Karthik Chandraraj


1 Answers

Use mongodb Long class. Something like this.

const Long = require('mongodb').Long;

var sequences = this.db.collection('sequences');
sequences.insert( {
    _id: "TEST_SEQ",
    value: Long.fromInt(1)
}, done);

Take a look here for more details

Mongo-db has default types it gives values, That's why it's inserted as an integer.

like image 74
Yaki Klein Avatar answered Sep 20 '25 14:09

Yaki Klein