Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What are the plans of Mongoose to support BigInt? #6936

Closed
koresar opened this issue Aug 29, 2018 · 11 comments
Closed

What are the plans of Mongoose to support BigInt? #6936

koresar opened this issue Aug 29, 2018 · 11 comments
Labels
Milestone

Comments

@koresar
Copy link

koresar commented Aug 29, 2018

Starting node.js v10.3 the new data type was introduced - BigInt. It's Stage 3 atm.

Are there any plans or work going to support it same as Number, Buffer, Date, Map etc are supported?

@Fonger
Copy link
Contributor

Fonger commented Aug 29, 2018

MongoDB does not support BigInt type atm.
As long as mongodb does not support it, mongoose shouldn't support it.

Creating a mongoose plugin for BigInt is possible though however you have to cast BigInt to string or binary in MongoDB.

@vkarpov15
Copy link
Collaborator

This is something we should be able to add for the future. JavaScript BigInts are just 64 bit ints, and MongoDB does support 64 bit ints, so we would just need to expand mongoose-long to cast BigInts. Should be doable.

@vkarpov15 vkarpov15 added this to the Parking Lot milestone Aug 29, 2018
@vkarpov15 vkarpov15 added the interop issue issue with interop between Mongoose and another npm module that is not a Mongoose prod dependency label Aug 29, 2018
@koresar
Copy link
Author

koresar commented Aug 29, 2018

So which is right Vitaliy?

Mongoose do not plan to support BigInt natively.

Mongoose plans to support BigInt natively.

Mongoose is indecisive at the moment.

@Fonger
Copy link
Contributor

Fonger commented Aug 29, 2018

@koresar Sorry I didn't know that BigInt was just 64 bit int so @vkarpov15 was right.

Mongoose will support BigInt because MongoDB has Long type (basically the same)
There's an existing plugin called mongoose-long which can store 64bit integer value. This is doable by casting BigInt to BSON.Long.

I think if if BigInt is out, it's time to consider support it by native. Not just in a plugin.
That's just my opinion though.

@koresar
Copy link
Author

koresar commented Aug 29, 2018

Great to hear!

BigInt is out since nodejs v10.3.

@koresar
Copy link
Author

koresar commented Aug 30, 2018

I've taken a deeper look at the BigInt. It's definition is: Arbitrary Precision Integer. This means they are not 64 bit ints.
https://github.com/tc39/proposal-bigint

Run this line in latest Chrome console:

const myBigInt = 2n**524288n;
console.log(myBigInt);

It will render 157828 characters long string!

So, @Fonger you were actually right in the beginning. I really doubt MongoDB would ever support this type of data. :)

Let me clarify for future: mongoose does not support ESNext BigInt natively and do not plan to.

Thanks you all!
Cheers.

@koresar koresar closed this as completed Aug 30, 2018
@vkarpov15
Copy link
Collaborator

Ah ok, I misread this part of the BigInt spec. This means we would need a new plugin, mongoose-long won't work. MongoDB does support storing binary data so we might store bigints using buffers. Thoughts?

@vkarpov15 vkarpov15 reopened this Sep 3, 2018
@vkarpov15 vkarpov15 added plugin and removed interop issue issue with interop between Mongoose and another npm module that is not a Mongoose prod dependency labels Sep 3, 2018
@koresar
Copy link
Author

koresar commented Sep 5, 2018

Sounds like a plan. The new plugin name better be mongoose-bigint (not yet taken).

@nodegin
Copy link

nodegin commented Apr 21, 2019

This is really needed, Node.js now support BigInt natively and we definitely do not want to deal with Decimal128.

@Fonger
Copy link
Contributor

Fonger commented May 8, 2019

The problem is that that MongoDB doesn't support BigInt at this moment.

You can always use Binary (Buffer with mongoose) to store BigInt, however, anything related to arithmetic update operations won't work. Comparison in Binary has unexpected behavior too. and mongoose can't handle that for you.

If what you want is just storing the value inside mongodb, you can use bigint-buffer to convert the value to buffer and then save it.

@vkarpov15
Copy link
Collaborator

@Fonger that's an interesting idea, we should be able to store BigInts as buffers, but then you won't be able to do $inc, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants