【问题标题】:How do I store Date objects in MongoDB that are cross compatible with Node.JS?如何在 MongoDB 中存储与 Node.JS 交叉兼容的 Date 对象?
【发布时间】:2022-01-05 10:39:53
【问题描述】:

我在我的 API 堆栈中同时使用 Node.js 和 Golang。我需要在 MongoDB 中存储 Date 对象,但在 Golang 中,我不确定如何创建在两种语言之间交叉兼容的 Date 对象。

如何在 golang 中创建 new Date() 以存储在 MongoDB 中?

【问题讨论】:

    标签: javascript node.js go time


    【解决方案1】:

    您是否使用驱动程序连接到 mongo?很可能它会处理 Go 中的 time.Time 类型和 mongo Date 类型之间的转换。

    编辑:为了清楚起见,请尝试:

    t := time.Now()
    

    并将 t 直接保存到您的 mongo 文档中

    【讨论】:

      猜你喜欢
      • 2018-06-28
      • 2019-08-24
      • 1970-01-01
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 2014-01-25
      • 1970-01-01
      相关资源
      最近更新 更多