按小时排序数据 | mongodb

Sort data by hours | mongodb

我开始使用 Meteor...所以我有以下格式的文档:

{
      "_id": 1,
      "name": "john",
      "time": "12:10:00"    
},
{
      "_id": 1,
      "name": "mark",
      "time": "10:10:00"    
},
{
      "_id": 1,
      "name": "bob",
      "time": "22:10:00"    
}

我如何按低时段到高时段排序,例如:10:10:00, 12:10:00, 22:10:00

我的代码:

Template.body.helpers({
    tasks: function(){
      return data.find();
    }
  });

html:

      <ul>
        {{#each tasks}}
          {{> task}}
        {{/each}}
      </ul>
      <template name="task">
        <li><span class="text">{{name}}</span>, <span class="time">{{time}}</span></li>
      </template>

您应该能够为查找函数提供第二个参数,用于排序。 {} 表示查找所有文档。

return data.find({}, { sort: { time: 1 } });