Flutter 云Firestore子集合访问
访问子集合时,是否应使用以下代码:Flutter 云Firestore子集合访问,flutter,dart,google-cloud-firestore,Flutter,Dart,Google Cloud Firestore,访问子集合时,是否应使用以下代码: DocumentSnapshot userSnapshot = await Firestore.instance .collection('users') .document(userId) .collection('shoppingLists') .document(listName) .get(); 或者这个: DocumentSnapshot userS
DocumentSnapshot userSnapshot = await Firestore.instance
.collection('users')
.document(userId)
.collection('shoppingLists')
.document(listName)
.get();
或者这个:
DocumentSnapshot userSnapshot = await Firestore.instance
.collection('users/$userId/shoppingLists')
.document(listName)
.get();
?
我喜欢第一种款式。它们转换为相同的I/O吗?结果没有差异 实际上,您甚至可以将第二个缩短为:
DocumentSnapshot userSnapshot=wait Firestore.instance
.document('users/$userId/shoppinglist/$listName')
.get();
来自:
Cloud Firestore中的每个文档或集合都通过其在数据库中的位置进行唯一标识,您可以创建指向它的引用。为方便起见,要访问Cloud Firestore分层数据模型,您可以通过将文档或集合的路径指定为字符串来创建引用,路径组件用正斜杠(/)分隔。
因此,您可以选择使用之前发布的两种方法中的任何一种,或者按照@AndreyGordeev的建议进一步缩短。这真的取决于你