When working with Firebase, I was able to successfully retrieve and print out a list of events. However, now I'm facing a challenge - I want to load only the "Events" that are not outdated. Any suggestions or tips on how to achieve this? I'd greatly appreciate your help. Thank you in advance :) - Max
loadEvents ({commit}) {
commit('setLoading', true)
firebase.database().ref('events').once('value')
.then((data) => {
const events = []
const obj = data.val()
for (let key in obj) {
events.push({
id: key,
title: obj[key].title,
day: obj[key].day,
description: obj[key].description,
imageUrl: obj[key].imageUrl,
date: obj[key].date,
location: obj[key].location,
creatorId: obj[key].creatorId
})
}
commit('setLoadedEvents', events)
commit('setLoading', false)
})
.catch(
(error) => {
console.log(error)
commit('setLoading', false)
}
)
},
UPDATE: Thanks to Frank, I can now filter out nodes based on the "expires" field. How can I specifically retrieve nodes where the date (timestamp) in the "expires" field is greater than yesterday's date?
loadMeetups ({commit}) {
commit('setLoading', true)
firebase.database().ref('Meetups').orderByChild('expires').startAt(Date.now()).once('value')
.then((data) => {
const Meetups = []
const obj = data.val()
for (let key in obj) {
Meetups.push({
id: key,
title: obj[key].title,
day: obj[key].day,
expires: obj[key].expires,
description: obj[key].description,
imageUrl: obj[key].imageUrl,
date: obj[key].date,
location: obj[key].location,
creatorId: obj[key].creatorId
})
}
Here's an example of how I push my data to Firebase:
methods: {
onCreateMeetup () {
if (!this.formIsValid) {
return
}
const MeetupData = {
title: this.title,
day: this.day,
expires: this.expires,
location: this.location,
imageUrl: this.imageUrl,
description: this.description,
date: this.submittableDateTime
}
this.$store.dispatch('createMeetup', MeetupData)
this.$router.push('/Meetups')
}
}
And here is a sample of my data
Best regards,