Reputation: 135
I have in firebase firestore
a Collection named users created with docs of unique id.
Now I would like to push them in an Array
.
(In the usersCollection there are 3 users stored with the currentUser.uid
)
Example:
fb.usersCollection.where("state", "==", 'online').get().then(querySnapshot => {
querySnapshot.forEach((doc) => {
const userName = doc.data().name
this.markerMy = { name: userName }
})
// push userName inside randomArray
const randomArray = []
randomArray.push(this.markerMy)
I only get it so that I can push one user inside the Array, but not more.
Upvotes: 1
Views: 797
Reputation: 1
You should declare randomArray
before fb.usersCollection
and call the push operation inside the callback as follows :
const randomArray = []
fb.usersCollection.where("state", "==", 'online').get().then(querySnapshot => {
querySnapshot.forEach((doc) => {
const userName = doc.data().name
this.markerMy = {
name: userName
}
randomArray.push(this.markerMy)
})
});
Upvotes: 3