抖动错误:文档引用必须具有偶数个段

问题描述 投票:0回答:2

我有一个名为memssages的集合,并且必须查找其中字段begin等于false的文档。代码如下。

Future<String> getRoomID() async {
  QuerySnapshot snapshot = await sl.get<FirebaseAPI>().getFirestore()
    .collection('messages')
    .where('begin',isEqualTo: false).getDocuments();
  if(snapshot.documents.length==0){
    return '';
  } else {
    Random random = Random();
    DocumentSnapshot document = snapshot.documents[random.nextInt(snapshot.documents.length)];
    return document.documentID;
  }
}  

但是它发生致命错误,例如我的帖子标题。

java.lang.IllegalArgumentException:无效的文档引用。文档引用必须具有偶数个段,但是消息有1

我怎么了?我整天都在受苦...

Database ScreenShot

dart flutter google-cloud-firestore fatal-error
2个回答
1
投票

集合引用将具有奇数个段,文档参考的段数为偶数。

Firestore数据结构为:收藏-文档-收藏-文档-收藏-文档

对于您的情况,您尝试从getDocument()调用collectionReference(odd segment),但是被调用的getDocument()之后的代码属于getDocumentdocumentReference(even segment)。因此,错误告诉您您的参考需要段的偶数


0
投票

以防万一,这可以帮助:

在获取之前转到实例

final ref = db.collection("users").document(uid).get(); 
print (ref.path); 
final snapShot = await ref;
© www.soinside.com 2019 - 2024. All rights reserved.