Flutter是否支持FieldPath?

6

我在 cloud_firestore Flutter 插件 中找不到 FieldPath,但我认为这是一个非常常见的工具,应该是此类插件中最先实现的之一。

最近添加了 FieldValue,但我找不到任何关于 FieldPath 的内容。
如果我想要在查询中使用 documentId,是否有方法可以实现?

2个回答

14

我其实忘记了这件事情,但我在某个时候的 pull request 中添加了 FieldPath.documentId 作为 cloud_firestore 的一部分。

这意味着你可以像这样简单地使用它:

Firestore.instance.collection('movies').orderBy('rating').orderBy(FieldPath.documentId);

已过时的

__name__可以用来定位文档id

您可以使用'__name__'作为String,它等同于FieldPath.documentId()

String fieldPathDocumentId = '__name__';

Firestore.instance.collection('movies').orderBy('rating').orderBy(fieldPathDocumentId);

请问您能否提供如何使用它的任何示例? - m-bhole
@creativecreatorormaybenot 如何使用__name__来获取documentId的实例? - alfiepoleon

4

这对我来说有效。(我不确定这是否是你想要的。)

Firestore.instance.collection('/collection-name')
  .where(FieldPath.documentId, isEqualTo: _someID)
  .snapshots().listen((snapshots){
    /*

    */
  });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接