Skip to content

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

@kuehn-sba

Description

@kuehn-sba

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions