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

I get different format for long values back since using mongoose 6.x #24

Open
kuehn-sba opened this issue Feb 12, 2025 · 0 comments
Open

Comments

@kuehn-sba
Copy link

kuehn-sba commented Feb 12, 2025

Has anything changed in the setup of mongoose 6.x? The way long datatypes are delivered by mongodb is different from the previous version of mongoose and I'm not sure how to correctly handle and transport values as (long) number in JS/JSON.

I have upgraded from MongoDB 5.x to MongoDB 6.x and Mongoose@5 to Mongoose@6. With 4.x and 5.x our client/server system works as it should.

An excerpt of the use in a scheme:

var Mongoose    = require('mongoose');

require('mongoose-long')(Mongoose);

var SchemaTypes = Mongoose.Schema.Types;
var MySchema = new Mongoose.Schema({
..
..
    timecode: {
        type: SchemaTypes.Long,
        min: 0, 
        default: 0
    },
..
});

and I retrieve the document using 'find':
MySchema.find(options).sort(sortBy).skip(from).limit(size).batchSize(1000000)

as a result, I get the field back as new Long(“1985962292388”) instead of Long {_bsontype: 'Long', low_: 1985962292, high_: 388 } since using mongoose 6.x

and if I output it as JSON.stringify, then the return value with mongoose 5.x is still a string and with mongoose 6.x an object in this format:

mongoose 5.x:

"timecode": "1733151474200",

mongoose 6.x:

    "timecode": {
        "low": -2015313384,
        "high": 403,
        "unsigned": false
    },

how should BSON be configured or evaluated in order to process the longs compatibly but correctly?

@kuehn-sba kuehn-sba changed the title I get 'new Long(“1668433278240”)' instead of 'Long {_bsontype: 'Long', low_: 1985962292, high_: 388 }'since using mongoose 6.x I get 'new Long(“1985962292388”)' instead of 'Long {_bsontype: 'Long', low_: 1985962292, high_: 388 }'since using mongoose 6.x Feb 12, 2025
@kuehn-sba kuehn-sba changed the title I get 'new Long(“1985962292388”)' instead of 'Long {_bsontype: 'Long', low_: 1985962292, high_: 388 }'since using mongoose 6.x I get different format for long values back since using mongoose 6.x Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant