node.js - 为什么我的时间戳字段在将数据嵌入到地图列表后变成时间图?
问题描述
我尝试将一些事件文档嵌入到用户文档中名为upcomingEvents
(地图列表)的字段中。
所以首先,我查询将像这样嵌入到用户文档中的事件文档
const willStartSoonEventsSnapshot = await db.collection('events')
.where("createdBy","==", event.createdBy)
.where("isActive","==", true)
.where("hasBeenApproved","==", true)
.where("dateTimeStart",">",now)
.limit(7)
.orderBy("dateTimeStart","asc")
.get()
然后我upcomingEvents
使用下面的代码更新用户文档中的字段
const upcomingEvents = []
willStartSoonEventsSnapshot.forEach( doc => {
upcomingEvents.push(doc.data())
})
// trying to log createdAt field
console.log(upcomingEvents[0].createdAt)
db.doc(`users/${event.createdBy}`).update({
upcomingEvents
})
从下图中可以看出,最初在events
集合中,createdAt
字段是时间戳数据类型
但是在我运行上面的代码并且数据已成功嵌入upcomingEvents
字段中的用户文档(地图列表)之后,createdAt 的时间将在地图中,而不是像这样的时间戳
正如您从上面的代码中看到的那样,我尝试记录 createdAt 时间戳,这是结果。有数据是时间戳数据类型
我正在使用 firebase 云功能来运行上面的代码
const admin = require("firebase-admin")
const functions = require('firebase-functions')
admin.initializeApp(functions.config().firebase)
那么,为什么我的时间戳字段会变成这样的地图?我可以将它保存在时间戳数据类型中吗?
解决方案
从您提供的数据来看,日期字段的属性似乎丢失了。如果正在对数据进行字符串化和解析,请检查代码。因为如果记录中有一个日期字段,你打印它,你会看到它是这样的。
{dateField:{纳秒:5651654613,秒:21356883213}}
那是从 firestore 的查询结果中收到的日期。如果属性丢失,则 Firestore 不会将其视为日期对象。
推荐阅读
- stanford-nlp - 模式不符合预期
- excel - 更新它所基于的数据透视表和链接表的问题
- sql - 使用 CLOB 将多行合并为单行
- d3.js - D3 v5 仅在 timeParse 中使用 Year
- node.js - 我该如何处理 SQLITE_CANTOPEN?
- html - 我的浏览器都没有拉 CSS divDisplay 代码,但 CodePen 拉
- oracle - C# Core,OracleDataReader,hasRows 为 false,同时选择表中包含数据的所有行
- android - 加载 Firebase 数据时,意图未通过单击传递
- java - Textfield 的文本更改事件
- java - 2 线程“主”java.util.NoSuchElementException 中的方法异常