简体   繁体   English

Javascript 函数 toLocaleString() Mongo DB 不工作

[英]Javascript Function toLocaleString() Mongo DB not working

On mongo shell we are trying to format output values for comma separated .在 mongo shell 上,我们试图格式化逗号分隔的输出值。 but mongo shell doesnt format the value.但 mongo shell 不会格式化该值。

Mongo Function On Shell:外壳上的 Mongo 函数:

db.system.js.save({_id:"testValue", value: function(){ 
            var number2 = 1234.56789;
            valueFormatted=numer2.toLocaleString(); 
             return valueFormatted }
})

output: 1234.56789 (* no effect of function)输出:1234.56789(*无功能影响)

Why is .toLocaleString() not working in mongo shell ?为什么.toLocaleString()在 mongo shell 中不起作用? Is any other way of formatting numbers to comma separated within in mongo functions ?在 mongo 函数中是否有任何其他方式将数字格式化为逗号分隔?

You can use date format command您可以使用日期格式命令

 db.system.js.save({_id:"testValue",
 date: { $dateToString: { date: new Date(), format: "%Y-%m-%d"} } })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM