firebase - Will i get the entire document from the firestore?
问题描述
hi. i have a database as in the picture above i have a smartphones collection with many documents(i.e. iphone or xiaomi) inside. i will use react to render this information and i want to load it from part to part. i.e. i want to render all of the smartphones on the main page and filter them... so for the main page i will only need description and ratings and for the full product details i will need tech specs and reviews. imagine that the whole document weight is 1mb 100kb both descriptions 200kb for tech specs 400kb reviews and 200kb ratings my question is:
- if i want to load only ratings and short description for the main page of 100 products. can i get only 300kb data from each product or i will get the whole 100mb data ???
- if i want to edit only camera 64mpx .. can i do this without getting all the document from the DB?
- is there any easy tool to add/edit/remove data in the firestore DB like MongoDBCompass ?
- any information about how read/add/edit operations works in firestore?
解决方案
if i want to load only ratings and short description for the main page of 100 products
You can load only ratings
as it's a document on it's own document. You cannot load only short description
as you cannot fetch a single field from a document. You'll get both short description
and full description
fields. (Do note that this won't include documents from the sub-collections i.e. reviews, tech specs in this case)
if i want to edit only camera 64mpx .. can i do this without getting all the document from the DB?
As long as you know ID of that document (smartphone document), you can using following update operation:
const phoneRef = firebase.firestore().collection("smartphones").doc("smart_phone_id")
const mediaRef = phoneRef.collection("tech_specs").doc("media")
mediaRef.update({ camera: "108px" })
is there any easy tool to add/edit/remove data in the firestore DB like MongoDBCompass ?
Firebase's console (where the screenshot is from) is one but there isn't any one click import built natively.
推荐阅读
- python-3.x - 参考基于python中其他文件的公共信息过滤的文件创建文件
- python - 在 python 中使用 Struct 打包 128 字节结构时出错
- c++ - BFS 遍历给出错误的输出
- python - Pandas Dataframes:列表中列的值是否嵌套在同一行的另一列中?
- python - 函数参数中的表达式理解
- pointers - 如何将不同的错误接口实现存储在一起,然后在 Go 中使用它们进行类型比较?
- python - Python - 根据变量触发特定函数
- relational-database - 这张表是 1NF 还是 2NF?
- babylonjs - 在网格点击时,ArcRotateCamera 专注于
- wpf - 在 ControlTemplate.Triggers 中查找 AncestorType 的问题