mongodb中如何将字符串时间格式转换为日期或时间
我在转换字符串时间格式时遇到问题,即 0h 0m 53s+695ms 到日期或时间 我有一个具有这种格式的持续时间字段,并且类型为 string ,我必须添加集合中与特定条件匹配的所有记录的持续时间。
但我收到如下错误: 无法解析 $convert 中的数字“0h 0m 53s+695ms”,且没有 onError 值:解析 0h 0m 53s+695ms 时出现错误的数字“h”(注意:如果我指定 onError,则结果只会填充错误条件) 诸如此类的还有很多。
关于如何将此特定类型转换为数据的任何线索?
I am facing issue while converting string time format i.e., 0h 0m 53s+695ms
to date or time
I have a duration field with this format and is of type string , I have to add the duration of all the records in the collection matching on certain condition.
But I am getting error like :
Failed to parse number '0h 0m 53s+695ms' in $convert with no onError value: Bad digit "h" while parsing 0h 0m 53s+695ms" (Note: if I specify onError than the result only get populates with error conditions)
and many more of such kind.
Any clue on how to convert this specific type to data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该聚合管道会将字符串转换为秒数。您可以总结一下:
您可以将输出格式化为如下形式:
This aggregation pipeline will convert the string into number of seconds. These you can sum up:
The output you can format like this: