0

In mongodb, it is possible to only return specific fields of a query:

db.inventory.find( { status: "A" }, { item: 1, status: 1 } )

Where fields Item and Status would be returned when Status is A.

Can I do the same with Firestore?

Sources: https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/

Joshua Hester
  • 117
  • 1
  • 8
  • For web and mobile clients, no. For server SDKs, use select(). – Doug Stevenson Aug 25 '20 at 18:54
  • Okay, I guess my solution is to create a subcollection then for web/mobile clients. I am surprised this isn't a feature by default – Joshua Hester Aug 25 '20 at 18:57
  • You can certainly split up document if that helps your case. – Doug Stevenson Aug 25 '20 at 19:01
  • I sent a feature request to Firebase. We will see what happens! – Joshua Hester Aug 25 '20 at 19:05
  • 2
    TBH, it's not likely to happen. A coherent caching strategy for the web and mobile SDKs depends on having the entire document in cache, or none at all. If the SDKs allow for partial documents, it becomes a lot more difficult to express via API if the cached document is complete or not. However you are free to make your own API that the clients can invoke to get partial documents, if you don't want caching. – Doug Stevenson Aug 25 '20 at 19:08
  • Okay, that logic makes a lot of sense then why it does not exist. Trying to minimize my server calls but I think I will have to structure my data a little differently. Thanks for the assist. – Joshua Hester Aug 25 '20 at 21:04

0 Answers0