Skip to content

snapshotChanges with orderByChild does not return data in correct order #1246

Closed
@kkbear1985

Description

@kkbear1985

Version info

**Angular:**4.1.3

**Firebase:**4.5.0

**AngularFire:**5.0.0-rc.2

Other (e.g. Ionic/Cordova, Node, browser, operating system): ionic-angular@3.6.1

How to reproduce these conditions

since i needed metadata with my app
so i followed the guide for angular version 5 update as in https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md

and my queries is simply as below, by ordering the last edit time and limit to the first 10
this.postRef = this.maxPost.switchMap(maxPost =>
db.list('/Categories/0/', ref =>
ref.orderByChild('last_update_time').limitToFirst(maxPost)).snapshotChanges().map(actions =>
{
console.log("action is ", actions);
return actions.map(action =>{
const $key = action.payload.key;
const data = { $key, ...action.payload.val() };
return data;
` })}));``

however the actions comeback are in incorrect order as you can see in
actions[3] (it return it's prevKey as -KvRz-nXZ1lReb_M3f5J but it is actually ordered after
and -KvSiF3pRpVcmzBN59gU)
actions[7](it return it's prevKey as -KvSiF3pRpVcmzBN59gU but it is actually ordered after
and -KvcFM0f7Rab-juFtjJG)

0:{type: "child_added", payload: DataSnapshot, prevKey: null, key: "-KvRz-nXZ1lReb_M3f5J"}
1:{type: "child_added", payload: DataSnapshot, prevKey: "-KvRz-nXZ1lReb_M3f5J", key: "-KvwLPrxfYSaQRackILo"}
2:{type: "child_added", payload: DataSnapshot, prevKey: "-KvwLPrxfYSaQRackILo", key: "-KvSiF3pRpVcmzBN59gU"}
3:{type: "child_added", payload: DataSnapshot, prevKey: "-KvRz-nXZ1lReb_M3f5J", key: "-Kw5AMnsYJo1ziebush6"}
4:{type: "child_added", payload: DataSnapshot, prevKey: "-Kw5AMnsYJo1ziebush6", key: "-KvPjv1fb7kmfEGSb32o"}
5:{type: "child_added", payload: DataSnapshot, prevKey: "-KvPjv1fb7kmfEGSb32o", key: "-Kvq8WyPLASUbMNQl8ox"}
6:{type: "child_added", payload: DataSnapshot, prevKey: "-Kvq8WyPLASUbMNQl8ox", key: "-KvcFM0f7Rab-juFtjJG"}
7:{type: "child_added", payload: DataSnapshot, prevKey: "-KvSiF3pRpVcmzBN59gU", key: "-KvuA2iMvvwbxf2prNYt"}
8:{type: "child_added", payload: DataSnapshot, prevKey: "-KvuA2iMvvwbxf2prNYt", key: "-Kw04p9MLnB3Gk4WUmKv"}
9:{type: "child_added", payload: DataSnapshot, prevKey: "-Kw04p9MLnB3Gk4WUmKv", key: "-KvwIav-C_c-38dPbmrh"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions