将 Firestore 中的 DocumentReference(s) 与 .where() 进行比较
Compare DocumentReference(s) in Firestore with .where()
如何比较DocumentReference引用?在此示例中(使用 Dart),我只想从特定用户那里获取票证。
late Query<Map<String, dynamic>> _query;
late DocumentReference<Map<String, dynamic>> _userDocumentReference;
_userDocumentReference = _firestore.collection('users').doc(userId);
_query = _firestore
.collection('tickets'),
//Does not work here
.where('user_id', isEqualTo: _userDocumentReference)
.orderBy('created_at', descending: isDesc)
.limit(7);
我通过在 FireStore 中创建索引找到了解决方案。检查您的调试控制台,因为它提供了一个 link 来自动为您的集合创建索引。
看起来像这样:
https://console.firebase.google.com/v1/r/project/{project}/firestore/indexes?create_composite=...,
如何比较DocumentReference引用?在此示例中(使用 Dart),我只想从特定用户那里获取票证。
late Query<Map<String, dynamic>> _query;
late DocumentReference<Map<String, dynamic>> _userDocumentReference;
_userDocumentReference = _firestore.collection('users').doc(userId);
_query = _firestore
.collection('tickets'),
//Does not work here
.where('user_id', isEqualTo: _userDocumentReference)
.orderBy('created_at', descending: isDesc)
.limit(7);
我通过在 FireStore 中创建索引找到了解决方案。检查您的调试控制台,因为它提供了一个 link 来自动为您的集合创建索引。
看起来像这样:
https://console.firebase.google.com/v1/r/project/{project}/firestore/indexes?create_composite=...,