Node.js MongoDB Driver Support For NumberDecimal (Decimal128) Format

929 views
Skip to first unread message

Robert Cochran

unread,
Jan 22, 2017, 9:45:08 PM1/22/17
to node-mongodb-native
I'm using the 'mongodb' version 2.2.21 Node.js driver with Node 7.4.0. I'm using MongoDB 3.4.1 on my server machine. Using the mongo shell, I created some documents which contain fields in NumberDecimal format. I wanted to aggregate these numbers using the aggregation pipeline (db.collection.aggregate(..)) I tested the aggregation in the mongo shell, on my server, and that works fine. I can see the aggregated NumberDecimal fields.

I am wondering if there is NumberDecimal support in node-mongodb-native 2.2.21? This driver seems to return aggregated decimal values to the Node script like this: 

[ { _id: '19',

    tot_miles: 

     Decimal128 {

       _bsontype: 'Decimal128',

       bytes: <Buffer 78 00 00 00 00 00 00 00 00 00 00 00 00 00 3c 30> },

    tot_points: 

     Decimal128 {

       _bsontype: 'Decimal128',

       bytes: <Buffer 64 00 00 00 00 00 00 00 00 00 00 00 00 00 3c 30> } },

  { _id: '18',

    tot_miles: 

     Decimal128 {

       _bsontype: 'Decimal128',

       bytes: <Buffer a4 06 00 00 00 00 00 00 00 00 00 00 00 00 3c 30> },

    tot_points: 

     Decimal128 {

       _bsontype: 'Decimal128',

       bytes: <Buffer a4 06 00 00 00 00 00 00 00 00 00 00 00 00 3c 30> } } ]


Is there a toString() method to support that? Can I add documents to the collection which contain NumberDecimal? 


If this is not yet supported, when might it be?


Thanks a ton


Bob Cochran

Greenbelt, Maryland, USA




 

christkv

unread,
Feb 13, 2017, 6:32:44 AM2/13/17
to node-mongodb-native
Decimal128 is supported as a BSON wrapper type. There was a bug in the doc generation that made it not show up correctly in the api docs. That should be fixed now

Reply all
Reply to author
Forward
0 new messages