Firestore get subcollection from where query

GusSL

I have a structure like this:

user/user_id/books/book_id

I'd like to get the collection of books of a user that have a specific phone. So I'd use:

firestore.collection('user').where('phone', '==', specificPhone)

But after that, how do I get the books subcollection? Do I have to manually do another query?

I only want to get the first coincidence, since where returns a set of results. Also I want to retrieve the data only once, not listen to changes.

Frank van Puffelen

Firestore reads are shallow; they don't read data from subcollections. So you'll indeed need to perform another read operation to get the books for the users that you found in your first query.

For example:

let user = await firestore.collection('user').where('phone', '==', specificPhone).get();
let books = await user.ref.collection("books").get();
books.forEach((bookDoc) => {
  console.log(book.id, book.data());
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Firestore - get the parent document of a subcollection

From Dev

How to get subcollection references in Firestore [Node JS]

From Dev

Can I query and retrieve Documents' field values in Subcollection in Cloud Firestore?

From Dev

Get Where Condition From SQL Query in java

From Java

Firestore "where" query not working as expected

From Dev

FIRESTORE - Insert a subCollection inside a document

From Dev

How to get variables from MSQL query with WHERE IN clause

From Dev

How to get variables from MSQL query with WHERE IN clause

From Dev

Parse where clause query from Rest Get call

From Dev

I can't use orderBy query from firestore if where is used Flutter

From Dev

Mongodb: How to get a list of subcollection

From Dev

Codeigniter get_where query

From Dev

Get id of where query in laravel

From Dev

SQL Query where I get most recent rows from timestamp from another table

From Dev

SQL Query to get data from one table where a specific column equals value from other table

From Dev

How to get an array from Firestore?

From Dev

Get Timestamp from Firestore databse

From Dev

Trying to get a String from the firestore

From Dev

Cloud Firestore query to get doc ID, Flutter

From Dev

Where to get TwitterCore from?

From Dev

Where to get TwitterCore from?

From Dev

Select from WHERE query not working

From Java

Query a single document from Firestore in Flutter (cloud_firestore Plugin)

From Java

Firestore: How to query data from a map of an array

From Dev

How to exclude an element from a Firestore query?

From Dev

Why does this query return nil from Firestore

From Dev

Why does the not equal to where clause query need an order by in firestore?

From Dev

Query Firestore field/value using multiple multiple 'where' values?

From Dev

Firestore query for a date field where the year does not matter

Related Related

  1. 1

    Firestore - get the parent document of a subcollection

  2. 2

    How to get subcollection references in Firestore [Node JS]

  3. 3

    Can I query and retrieve Documents' field values in Subcollection in Cloud Firestore?

  4. 4

    Get Where Condition From SQL Query in java

  5. 5

    Firestore "where" query not working as expected

  6. 6

    FIRESTORE - Insert a subCollection inside a document

  7. 7

    How to get variables from MSQL query with WHERE IN clause

  8. 8

    How to get variables from MSQL query with WHERE IN clause

  9. 9

    Parse where clause query from Rest Get call

  10. 10

    I can't use orderBy query from firestore if where is used Flutter

  11. 11

    Mongodb: How to get a list of subcollection

  12. 12

    Codeigniter get_where query

  13. 13

    Get id of where query in laravel

  14. 14

    SQL Query where I get most recent rows from timestamp from another table

  15. 15

    SQL Query to get data from one table where a specific column equals value from other table

  16. 16

    How to get an array from Firestore?

  17. 17

    Get Timestamp from Firestore databse

  18. 18

    Trying to get a String from the firestore

  19. 19

    Cloud Firestore query to get doc ID, Flutter

  20. 20

    Where to get TwitterCore from?

  21. 21

    Where to get TwitterCore from?

  22. 22

    Select from WHERE query not working

  23. 23

    Query a single document from Firestore in Flutter (cloud_firestore Plugin)

  24. 24

    Firestore: How to query data from a map of an array

  25. 25

    How to exclude an element from a Firestore query?

  26. 26

    Why does this query return nil from Firestore

  27. 27

    Why does the not equal to where clause query need an order by in firestore?

  28. 28

    Query Firestore field/value using multiple multiple 'where' values?

  29. 29

    Firestore query for a date field where the year does not matter

HotTag

Archive