【问题标题】:AttributeError: 'CollectionReference' object has no attribute 'orderBy'AttributeError:“CollectionReference”对象没有属性“orderBy”
【发布时间】:2020-07-13 03:13:03
【问题描述】:

我正在尝试按字段名称订购 firestore 集合,但它给了我这个错误:AttributeError: 'CollectionReference' object has no attribute 'orderBy'。

我的代码:

participants_ref = db.collection("participants")
docs = participants_ref.orderBy("name").stream()

如果这有帮助,我还打印了参与者参考,我得到以下信息:

【问题讨论】:

    标签: python firebase google-cloud-firestore


    【解决方案1】:

    根据documentation,你要找的方法是order_by。请务必将代码语言选项卡切换到“Python”以查看正确用法。

    docs = participants_ref.order_by("name").stream()
    

    另见python API documentation for CollectionReference

    【讨论】:

    • 哇,我觉得自己像个傻瓜:") 我使用的参考与 python 包大多相似,所以我没有意识到这是不同的。谢谢!
    猜你喜欢
    • 2012-12-01
    • 2021-04-19
    • 2021-01-08
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多