I am using a collection in Mongo with a price field with multiple money type :
{
price: '15 gp' // 15 gold pieces
}
or
{
price: '4 sp' // 0.4 gold pieces
}
I'm looking for a way to modify this field before querying the collection.
For example doing string modifications to remove the gp/sp and doing math operations to have a correct price in "GP" (1 GP = 10 SP)
This would help ordering the collection since mongo can't understand that 10 sp < 2 gp.
Is there a way to use Aggregation and regex to do it ?
$replaceOneaggregate operator (MongoDB v5.x).$replaceOnewould replace the whole document with an other. I'm looking for a way to "format" the price field to remove the "gp", "sp" and use the same money.