mongo-dart / mongo_dart

Mongo_dart: MongoDB driver for Dart programming language
https://pub.dev/packages/mongo_dart
MIT License
446 stars 98 forks source link

When I upgrade to 0.10.0 that bson is ^5.0.0, the ObjectId() on web throw error: Unsupported operation: Int64 accessor not supported by dart2js. #357

Closed yangfanyu closed 8 months ago

yangfanyu commented 8 months ago

I compared the code about ObjectId() in bson ^4.0.0 and bson ^5.0.0:

In bson ^4.0.0:


  static BsonBinary createId(int seconds, bool clientMode) {
    String getOctet(int value) {
      var res = value.toRadixString(16);
      while (res.length < 8) {
        res = '0$res';
      }
      return res;
    }

    if (clientMode) {
      var s = '${getOctet(seconds)}${getOctet(Statics.randomId)}'
          '${getOctet(Statics.nextIncrement)}';
      return BsonBinary.fromHexString(s);
    } else {
      return BsonBinary(12)
        ..writeInt(seconds, endianness: Endian.big)
        ..writeInt(Statics.randomId)
        ..writeInt(Statics.nextIncrement, endianness: Endian.big);
    }
  }

In bson ^5.0.0:


  /// creates a BsonBinary representation of this ObjectId with the given number
  /// of seconds sinceEpoch
  static BsonBinary createId(int seconds) => BsonBinary(12)
    ..writeInt(seconds, endianness: Endian.big)
    ..setIntExtended(_randomValue, 5)
    ..setIntExtended(_nextIncrement, 3, endianness: Endian.big);

then I change the code in bson ^5.0.0 to :


  /// creates a BsonBinary representation of this ObjectId with the given number
  /// of seconds sinceEpoch
  static BsonBinary createId(int seconds) => BsonBinary(12)
        ..writeInt(seconds, endianness: Endian.big)
        ..writeInt(Statics.randomId)
        ..writeInt(Statics.nextIncrement, endianness: Endian.big);

every thing is ok.

best regards.

giorgiofran commented 8 months ago

Thanks, I will check this issue ASAP.

giorgiofran commented 8 months ago

Uploaded a fix. Can you please give me a feedback? Thanks in advance!

yangfanyu commented 8 months ago

@giorgiofran Thanks, this problem is fixed in bson 5.0.3