Reputation: 591
I'm noticing the last document gets pushed twice into the array but the first document doesn't get pushed in at all. What gives? So it turns out it's not a problem with the date, something is up with the query, I think
let obj = {}
let items = []
db.collection('customer').doc(id).collection('appointments').get().then((snapshot) => {
snapshot.forEach((item) => {
let data = item.data()
console.log(item.id)
obj.start = data.start.toDate()
obj.end = data.end.toDate()
obj.title = data.title
obj.desc = data.desc
//console.log(date)
items.push(obj)
//console.log(items.length)
})
Upvotes: 0
Views: 97
Reputation: 1286
From what I can surmise, you're using an object reference to push into the array. Whenever that object gets changed, all the references of that object in that array will automatically change. So you might see regardless of the number of items you push, all of them will be the last document data.
you can try moving
let obj = {}
to
>let obj = {}
let data = item.data()
here, inside the loop.
Let me know if this works!!
Upvotes: 3