cdimascio / uuid-mongodb

📇 Generates and parses MongoDB BSON UUIDs
MIT License
100 stars 17 forks source link

Mongoose 5.13.8 troubles #56

Open Able1991 opened 2 years ago

Able1991 commented 2 years ago

Hello there. Not work implementation from examples with MUUID.from(this._id).toString(); this._id - is mongo lib object Now if fix with

_id: {
  type: Buffer,
  subtype: 4,
  default: () => MUUID.v1(),
},

....

// virtual getter for custom _id
schema
  .virtual("id")
  .get(function () {
    return MUUID.from(this._id.toBSON()).toString();
  })
  .set(function (val) {
    this._id = MUUID.from(val);
  });

Is this a normal solution, or is it necessary to do something else?

Mod5ied commented 6 days ago

Hey how did you fix this!!