0
votes

Hi Everyone I have users being able to upload images and the firestore document associated with the firebase storage, the firestore document has the user that uploaded its firebase uid.

I am trying to query for all images that have that uid in the collection. As you can see I am trying to use the current users uid that is stored in state.

created() {
    var assetsRef = db.collection('Assets')
    var query = assetsRef.where('user', '==', this.$store.state.user)
    console.log(query)
}

A Doc from firestore looks like this:

    authors
(array)
0
"bakerMan"
description
"Delicous chocolate chip cookies"
imageurl
0
"https://firebasestorage.googleapis.com/v0/b/hydra-games.appspot.com/o/whitney-wright-282066-unsplash.jpg?alt=media&token=fba56452-4eee-4e02-9cfa-f993723f2bdd"
slug
"the-best-cookies-ever"
title
"The Best cookies ever"
user
"qwrNDu4ViAOl1y6RCGZ6F9xHywX2"

I am trying to get that user id above to be able to allow me to return the whole document.

It returns:

Query$$1 {_query: Query, firestore: Firestore}
firestore: Firestore {_dataConverter: UserDataConverter, …}
_query: Query {path: ResourcePath, explicitOrderBy: Array(0), filters: Array(1), limit: null, startAt: null, …}
__proto__: Object

I cannot seem to find my doc information within the object.

thanks for any help

1

1 Answers

0
votes

Your code builds a query, but is not executing that query yet. To execute the query, you need to either call get() (to get the results once) or onSnapshot() (to start monitoring) on the query. So for example:

query.get().then((querySnapshot) => {
  querySnapshot.forEach((doc) => {
    console.log(doc.data());
  });
})

Note that this is covered quite well in the Firebase documentation, so I highly recommend spending some time there. For example, in the documentation on getting documents from a collection.