Mongo writes are quoted, causing some numeric fields to be of type String. Change the field type to be numeric.
db.Report99.find().forEach( function(doc){ db.Report99.update({'_id': doc._id},{$set:{"begin-quantity": parseFloat(doc["begin-quantity"])}}); / / to floating-point db. Report99. Update ({" _id ": doc. _id}, {$set: {" end - quantity" : NumberInt (doc/" end - quantity ")}}); });
Mongo 4.2+ version, can be parameter in the following way:
db.getCollection("my-report").update( { "begin-quantity": { $type: "string" } }, [{ $set: { "begin-quantity": {$convert: {input: "$business - quantity,", "double"}}}}], / / effective type: string|bool|int|long|double|decimal|date|timestamp|objectId ... { multi: true } )
[‘ my-report’] [‘ my-report’] [‘ my-report’] [‘ my-report’] [‘ my-report’] [‘ my-report’]
This article by the blog multiple platform
OpenWriteRelease!