Filter Firestore Collection by Document Reference-Console - firebase

How does one filter a Firestore collection by a document reference in the web console? For example, I have a collection that references another collection document called challenges.
But no matter what combination I use to try to filter that collection by the challenge ID it returns no results. I need to be able to do this so I can look at all of the documents in this collection that reference back to that particular challenge reference.
I am assuming this is possible in the console, but maybe it is not?

Related

FIRESTORE: Query collectionGroup by Document ID [duplicate]

So few day ago I moved my apps posts to cloud firestore from realtime database because of the more flexable querying that firestore apparently has. I have been modifying my code to work with firestore as the new database. Now I ran into a problem. How can I retrieve every document within "Posts" collection that has "Likes" collection that contains a specifically named document? I don't know if that makes sense so here's an image showcasing the problem:
I had a working query for firebase realtime database but can't figure out how to do it with firestore. Is it possible or do I have to change the structure of my database? If I do have to change the structure, what would be the most convenient way of getting the same result?
This is currently not possible with collection group queries. You might be tempted to put a filter on the query for FieldPath.documentId() == 'your-doucment-id', but that just isn't supported. FieldPath.documentId() is actually a token that refers to to fully unique document id, which includes the entire path of the document.
The workaround is to store the document ID as a field in the document, and filter on the contents of that field instead. So, if the document had a field called id with the ID of the document, you could query for collectionGroup("Likes").whereEquals('id', 'your-document-id').

Correlating Firestore indexes to slugs in a webapp

I'd like my web app router slugs to correspond to my Firestore documents data.
For example:
www.mysite.com/restaurants/burger-king
/restaurants <- Firestore Collection
/restaurants/mcdonalds <- Firestore Document
/restaurants/burger-king <- Firestore Document
This is easy enough, as I can assign the name as a slug-friendly UID in Firestore. The difficulty arises with CRUD functionality. I need to be able to rename my item titles, but Firestore does not permit you to rename indexes, which is the issue I'm facing.
One SO solution I saw was to delete the old record and creates a new one at the updated index. That's problematic for me, because sub-collections would be hard to transfer from the client side.
Are there more elegant solutions?
You don't have to identify a document by its ID. If you're able to ensure uniqueness of a document field value, you could instead query a collection for an ID value in a known field, then use the results of that query to satisfy your REST API. Then, you can change the value of that document field as often as you want, in order to satisfy required changes to the public API.

how to retrieve data from fire-store document collection data with out mentioning specific collection name?

I am working on angular 5 with firebase firestore.I inserted data into fire-store collection/document/collection/document/collection/document then set data the last document.But at the time retrieving data I am giving only first collection name then I want complete root data.but I am getting only field in it.
https://firebase.google.com/docs/firestore/query-data/get-data
checkout:List subcollections of a document
As we know querying in Cloud Firestore is shallow by default. This type of query isn't supported, although it is something Google may consider in the future.

Resolve Firestore References

Firebase Firestore has a reference type while defining fields of a document which allows us to add a reference to another document via its "Document path".
For example, I have the document animals/3OYc0QTbGOTRkhXeiW0t, with a field name having value Zebra. I reference it in the array animals, of document zoo/xmo5wX0MLUEbfFJHvKq6. I am basically storing a list of animals in a zoo, by referring the animals to the corresponding animal document in the animals collections.
Now if I query a specific document from the zoo collection, will references to the animals be automatically resolved? Will I the get the animal names in the query result? If not, how can I achieve this?
All document queries in Firestore are shallow, meaning that you only get one document in return for each document requested.
References in a document are not automatically fetched - you will have to make subsequent queries using the references in the document to get those other documents on your own.
Same thing with documents in subcollections - they require separate queries.

How to create a Collection of References in Firebase Firestore DB?

Im looking to have a document, which contains a collection of references to other documents. Like a Project that has a collection of Users, but the entries are Reference types to users from the top level Users collection.
I can't see a way of adding a Reference type to a Collection, It looks like you must create a Document first and then have a field in that doc that is the reference to the user doc - but that is just adding extra work.
When getting the collection data, you will have to first get the Document in the collection, and then using the field for the reference get the User Document.
It would be far simpler to have a nested array of values.
What is the best way to store a collection of references ?
A Reference is a field type, and fields must be in documents. You indeed cannot add References directly to a collection. But from your description I don't think this requires extra dummy documents:
Im looking to have a document, which contains a collection of references to other documents. Like a Project that has a collection of Users, but the entries are Reference types to users from the top level Users collection.
This sounds like you have two top-levels collections: Projects and Users. A document under Projects then has a nested map of user references.
If I misunderstood your model, then indeed: you will need to create a document to store your references to users. This is inherent to the Firestore data model, and can't be changed.

Resources