2016-10-12 5 views
0

私は流星/モンゴーでイオン2を使用しています。流星カーソルの並べ替え

私はCursorをソートしようとしていますが、アイテムが挿入された元の順序を保持しているだけです。私は、このトンを期待しているだろう

モデル

interface Chat { 
    _id?: string; 
    memberIds?: string[]; 
    title?: string; 
    subTitle?: string; 
    picture?: string; 
    lastMessage?: Message; 
    lastMessageCreatedAt?: Date; 
    receiverComp?: Tracker.Computation; 
    lastMessageComp?: Tracker.Computation; 
    } 

TS

private sortLocalChats(): void { 
    this.localChatCursor = this.localChatCollection.find({}, { sort: { lastMessageCreatedAt: -1 } }); 
    this.localChatCursor.forEach((chat: Chat) => { 
     console.log(chat.title+' '+chat.lastMessageCreatedAt); 
    }); 
    console.log('==> loaded sorted local chats: ' + this.localChatCollection.find().count()); 

出力

Ashton Marais Thu Oct 06 2016 16:50:36 GMT+0800 (CST) 
Ashton Marais Wed Oct 12 2016 21:20:18 GMT+0800 (CST) 
ghjghj ghjghg Wed Oct 05 2016 23:37:49 GMT+0800 (CST) 
Brett Simpson Thu Oct 06 2016 23:52:05 GMT+0800 (CST) 
==> loaded sorted local chats: 4 

o lastMessageCreatedAtでソートしてください。

助けてください。

答えて

0

ソート結果を取得するには、fetch()を最初に呼び出す必要があります。したがって、上記の例では、これは動作します:

this.localChatCursor.fetch().forEach(...); 
関連する問題