问题
I want to get full number as a String
, but instead "1490650000000"
it returns scientific notation "1.49065e+12"
Here's how I try to convert it:
{$substr: ["$myNumber", 0, -1]};
Any ideas how to prevent it?
Note:
I'm using v3.6 and can't upgrade to use $toString
(thanks mlab).
回答1:
If you have mongodb 4.0 then you can use $toLong aggregation
db.collection.aggregate([
{
"$project": {
"myNumber": {
"$toLong": "$myNumber"
}
}
}
])
回答2:
You can try as below.
db.collectionName.aggregate([
{ $addFields: { "strFld": {$toString: {$toLong:"$numberFiled"}}} },
])
来源:https://stackoverflow.com/questions/51230909/mongodb-converts-number-to-string-in-scientific-notation