In the MongoDB shell, I can insert an integer value of 1 by using the NumberInt(1) type coercion.
How can I do that from client JavaScript that uses the mongodb module?
The Node.js MongoDB driver API exposes three integer types:
Choose the one that best fits your data range and use it like this:
import MongoClient from 'mongodb';
//...
MongoClient.Int32(1)
MongoClient.Long(2)
MongoClient.Decimal128(3)
var NumberInt = require("mongodb").Int32;
var dataToInsert = NumberInt(1)
Now this can be used wherever you would want to insert a value as Int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With