I have a collection of bar orders, and in each document i have a field with a reference for a barman.
I'm trying to made a where with the doc reference.
Something like that:
orders = this.database.collection("orders",
(ref) => ref.where("barman.path", "==", "barmen/" + this.auth.auth.currentUser.uid),
);
return orders.valueChanges();
barman.path
because when i get a doc with a field referece, this is the way to get the reference path.
I already tried to use just barman
instead barman.path
.
I already tried to made where with full 'path' of docref (firestore.googleapis.com/pro...
).
Any ideas?
Put only the id instead of the full reference will dificult other parts of the system.
How to get query data using firebase firestore? Simply, use a get() call! query. get().
A DocumentReference refers to a document location in a Cloud Firestore database and can be used to write, read, or listen to the location. There may or may not exist a document at the referenced location. A DocumentReference can also be used to create a CollectionReference to a subcollection.
In order to query a reference field, you should create a DocumentReference
object that matches the location you are trying to query for, and use that. Note that this needs to be a native Firestore reference, as an AngularFirestoreCollection
and AngularFirestoreDocument
will just show up to Firestore as a "custom object type". You can get this with the ref
member of the AngularFirestore types.
I'm not sure where the '.path' part of your query is coming form, as the actual field you are querying for is barman
. I've removed it in the example.
In your case, this will look something like:
const queryReference = this.database
.collection('barmen')
.doc(this.auth.auth.currentUser.uid).ref;
orders = this.database.collection('orders',
(ref) => ref.where('barman', '==', queryReference),
);
return orders.valueChanges();
I obviously couldn't test this exactly as there isn't enough code to, for example, show that this.auth.auth.currentUser.uid
works in this case. But it should point you in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With