async () => {
const doc = await firestore().collection("queue").where("order_id", "==", elem.orderID)
}
Here is the code of mine. The question is, how to update a document without knowing its document ID. Is it feasible by a query?
async () => {
const doc = await firestore().collection("queue").where("order_id", "==", elem.orderID)
}
Here is the code of mine. The question is, how to update a document without knowing its document ID. Is it feasible by a query?
With firestore().collection("queue").where("order_id", "==", elem.orderID)
you just define a Query
but you don't fetch any data.
I make the assumption that this query will return a unique document. Therefore you need to execute the Query
with the get()
method and, then, update the unique document returned by the Query, as follows:
async () => {
const querySnapshot = await firestore().collection("queue").where("order_id", "==", elem.orderID).get();
await querySnapshot.docs[0].ref.update({...})
}
Note how we use the docs
property of the QuerySnapshot
which returns "an array of all the documents in the QuerySnapshot
."