Reputation: 333
I am trying to get Events from my Firebase database, but I have no idea, why I got this error :
Unhandled Rejection (FirebaseError): Function DocumentSnapshot.get() requires between 1 and 2 arguments, but was called with 0 arguments.
I have used very similar way in other components and everthing was right then...
const getEvents = async () => {
const ref = await firebase.firestore().collection('uzytkownik').doc(selectedUser);
firebase.firestore().collection('wydarzenie')
.where("uczestnicy", "array-contains", ref).get()
.then(async resp => {
console.log(resp)
const new_array = await Promise.all(resp.docs.map(event => {
console.log(event)
return event.get().then(resp => {
let new_event = {
...resp.data(),
id: resp.id
}
return new_event;
})
}))
console.log(new_array)
setUserEvents(new_array)
})
}
Upvotes: 0
Views: 217
Reputation: 598765
As far as I can see, you're looking for this:
const ref = await firebase.firestore().collection('uzytkownik').doc(selectedUser);
firebase.firestore().collection('wydarzenie')
.where("uczestnicy", "array-contains", ref).get()
.then(async snapshot => {
const new_array = snapshot.docs.map(doc => {
return {
...doc.data(),
id: doc.id
}
})
}))
console.log(new_array)
setUserEvents(new_array)
})
At the end of this the console.log(new_array)
will log data and ID of all documents that match the query.
Upvotes: 1