dongsheng4679 2019-02-18 14:51
浏览 12

按时间戳对Firebase查询进行排序似乎会返回0个结果[使用编程语言]

Problem Overview:
I'm querying a "Sessions" collection for sessions with a UserID == string, this works fine. But when I try and OrderBy("DateCreated", Desc) which is of type timestamp I get 0 results

What I've tried:
I've checked the DB and the property I'm using which is called "DateCreated" and it's a valid timestamp type. All sessions data is generated in go with random date ranges.

Current Results:
returns 100 results (correct)
firstSessionQuery := db.Collection("Sessions").Where("UserID", "==", uid).Documents(ctx)

returns 0 results VS 100 (incorrect)
firstSessionQuery := db.Collection("Sessions").Where("UserID", "==", uid).OrderBy("DateCreated", firestore.Asc).Documents(ctx)

firstSessionQuery := db.Collection("Sessions").Where("UserID", "==", uid)
allDocs, err := firstSessionQuery.Documents(ctx).GetAll()

docsSorted := firstSessionQuery.OrderBy("DateCreated", firestore.Asc).Documents(ctx)
allDocsSorted, err := docsSorted.GetAll()
fmt.Printf("docs len: %v, docs sorted len: %v
", len(allDocs), len(allDocsSorted))

the first %v returns 100, second %v returns 0

Expected results:
My expected results are 100 sessions sorted by date, either ascending or descending.

Here are db screenshots:
here is the DateCreated prop

Here is the UserID prop

Terminal fmt printout

  • 写回答

2条回答 默认 最新

  • dougou1127 2019-02-18 15:45
    关注

    That work for me in a similar context

    db.collection("Sessions")
                .orderBy("DateCreated", Query.Direction.ASCENDING)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)