Home > other >  Automatically parse some fields to string on mongoose?
Automatically parse some fields to string on mongoose?

Time:01-17

I have an object that looks like this

{
  name: 'abc',
  value: BigNumber('125'),
  other: {
    otherValue: BigNumber('252'),
  }
}

Its mongoose schema is:

{
  name: { type: String, required: true },,
  value: { type: String, required: true },,
  other: {
    otherValue: { type: String, required: true },,
  }
}

Is there a way to automatically parse value and otherValue to string (by calling .toString()) before storing the object or the only way is to do it by hand?

CodePudding user response:

Mongoose allows a enter image description here

  •  Tags:  
  • Related