Firebase - 基于分区偏移逻辑的查询
Firebase - Query based on partitioned offset logic
我正在 Angular 4 中创建一个聊天应用程序,它在 Firebase 数据库中存储和读取消息。
我编写了一个查询以仅检索该特定对话的最新 10 条消息。
this.messages = this.db.list('messages/' + conversationId, { query: { limitToLast: 10 } });
db:AngularFireDatabase,消息:FirebaseListObservable
现在我想在有人按下 'more' 按钮(或滚动到顶部)时检索 10 条较旧的消息,而我为此编写查询时遇到困难。
这是我试过的:
this.messages = this.db.list('messages/' + conversationId, { query: { orderbyChild: 'id', startAt: start, limitToLast: 10 } });
'start' 这里有一个像 '-KovtCl4hEUPR2LfQfpc' 这样的 id,它是 this.messages FirebaseListObservable 中最早的消息的 id。我还尝试手动将此 ID 作为字符串传递给执行上述查询的方法。
尝试按照此处所述进行操作:
- https://firebase.google.com/docs/reference/android/com/google/firebase/database/Query
- https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
最后一个查询给了我 0 个结果。
Firebase 布局
/messages/conversationId/messageId/{留言}
"messages": {
"-k32b": {
"-kT3d": {
"content": "Hello World!",
"id" : "-kT3d"
},
"-kT4c": {
"content": "How are you World?",
"id" : "-kT4c"
}
}
}
我做错了什么?
也考虑使用“endat”。
查看 this tutorial 了解详细说明。
PS我在phone,我稍后会重新格式化。
事实证明,由于查询中的拼写错误('orderbyChild' 而不是 'orderByChild'),它无法正常工作。感谢 Firebase 没有给我任何错误 here:p
我现在确实在方法链中一起使用 .orderByChild()、.endAt() 和 .limitToLast()。这确保了查询条件以正确的顺序执行,而在查询对象中查询 this 似乎没有特别的顺序执行这些条件。
我正在 Angular 4 中创建一个聊天应用程序,它在 Firebase 数据库中存储和读取消息。
我编写了一个查询以仅检索该特定对话的最新 10 条消息。
this.messages = this.db.list('messages/' + conversationId, { query: { limitToLast: 10 } });
db:AngularFireDatabase,消息:FirebaseListObservable
现在我想在有人按下 'more' 按钮(或滚动到顶部)时检索 10 条较旧的消息,而我为此编写查询时遇到困难。
这是我试过的:
this.messages = this.db.list('messages/' + conversationId, { query: { orderbyChild: 'id', startAt: start, limitToLast: 10 } });
'start' 这里有一个像 '-KovtCl4hEUPR2LfQfpc' 这样的 id,它是 this.messages FirebaseListObservable 中最早的消息的 id。我还尝试手动将此 ID 作为字符串传递给执行上述查询的方法。
尝试按照此处所述进行操作:
- https://firebase.google.com/docs/reference/android/com/google/firebase/database/Query
- https://firebase.google.com/docs/database/web/lists-of-data#filtering_data
最后一个查询给了我 0 个结果。
Firebase 布局
/messages/conversationId/messageId/{留言}
"messages": {
"-k32b": {
"-kT3d": {
"content": "Hello World!",
"id" : "-kT3d"
},
"-kT4c": {
"content": "How are you World?",
"id" : "-kT4c"
}
}
}
我做错了什么?
也考虑使用“endat”。
查看 this tutorial 了解详细说明。
PS我在phone,我稍后会重新格式化。
事实证明,由于查询中的拼写错误('orderbyChild' 而不是 'orderByChild'),它无法正常工作。感谢 Firebase 没有给我任何错误 here:p
我现在确实在方法链中一起使用 .orderByChild()、.endAt() 和 .limitToLast()。这确保了查询条件以正确的顺序执行,而在查询对象中查询 this 似乎没有特别的顺序执行这些条件。