I have written millions of documents with $CURRENT_CASH_BALANCE as strings instead of decimals. How can I convert them all to decimals?
Mongodb – Mongo: how to covert a string to decimal
decimalmongodbtype conversion
Related Question
- PostgreSQL – Convert Latitude and Longitude from Varchar to Numeric
- SQL Server – Convert String Numeric Values with Comma as Decimal Separator to NUMERIC(10, 2)
- MongoDB Type Conversion – How to Convert _id Field from String to Number
- SQL Server – Why is Datalength of Decimal 5 Regardless of Precision?
- Update String Field to Integer in MongoDB – How to Guide
- PostgreSQL – Cast String to Decimal Without Rounding the Decimal Part
- MongoDB Sharding – Logic Behind Forming Ranges for Hexadecimal String
Best Answer
Consider a collection with documents:
The following command can be run from the
mongo
shell to update the two documents with the fieldbal
canverted from string data type to NumberDecimal:After the update, the documents: