MongoDB sorting

前端 未结 4 1594
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 13:23

I want implement a \"bump\" feature for topics. Once a topic is bumped, it will have a new \"bump_date\" field. I want to sort it so that when there is a \"bump_date\" fie

4条回答
  •  孤街浪徒
    2020-12-13 13:33

    As Brian Hicks suggested, creating an additional updated_at field is the way to go. This way, when a document is created you can have created_at and updated_at initially be the same.

    {
         "created_at": xxx,
         "updated_at": xxx
    }
    

    If you then "bump" the updated_at field by setting it to the current time when there is a a bump event you can sort on the updated_at field to achieve the ordering you desire.

提交回复
热议问题