Meteor JS $靠近Reactive Sorting

Ada*_*ine 3 mongodb meteor

我很高兴看到近期对地理空间指数的支持最近被添加到Meteor 0.6.6中的minimongo.但是,$ near(它应按距离排序)的排序行为似乎不具有反应性.也就是说,当文档被添加到集合中时,客户端会加载它,但始终在结果列表的末尾,即使它比其他文档更接近$ near坐标.刷新页面时,订单已更正.

例如:

服务器:

Meteor.publish('events', function(currentLocation) {
    return Events.find({loc: {$near:{$geometry:{ type:"Point", coordinates:currentLocation}}, $maxDistance: 2000}});
});
Run Code Online (Sandbox Code Playgroud)

客户:

Template.eventsList.helpers({
    events: function() {
        return Events.find({loc: {$near:{$geometry:{ type:"Point", coordinates:[-122.3943391, 37.7935434]}}, 
$maxDistance: 2000}});
    }
});
Run Code Online (Sandbox Code Playgroud)

有没有办法让它被反应排序?

ims*_*vko 7

$near查询的反应性排序为minimalongo中的任何其他查询没有什么特别之处:minimongo根据查询中传递的排序说明符或包含$near运算符的查询的默认排序使用一些排序函数.

Minimongo会对所有内容进行排序,并在每次更新时将先前的订单与新订单进行比较.

从你原来的问题来看,目前还不清楚你期望的行为以及你看到的是什么.为了证明提到的排序是反应性的,我写了一个迷你应用程序来表明它:

html模板:

<body>
  {{> hello}}
</body>

<template name="hello">
  Something will go here:
  {{#each things}}
    <p>{{name}}
  {{/each}}
</template>
Run Code Online (Sandbox Code Playgroud)

和JS文件:

C = new Meteor.Collection('things');

if (Meteor.isClient) {
  Template.hello.things = function () {
    return C.find({location:{$near:{$geometry:{type: "Point",coordinates:[0, 0]}, $maxDistance:50000}}});
  };

}

if (Meteor.isServer) {
  Meteor.startup(function () {
    C.remove({});

    var j = 0;
    var x = [10, 2, 4, 3, 9, 1, 5, 4, 3, 1, 9, 11];

    // every 3 seconds insert a point at [i, i] for every i in x.
    var handle = Meteor.setInterval(function() {
      var i = x[j++];
      if (!i) {
        console.log('Done');
        clearInterval(handle);
        return;
      }

      C.insert({
        name: i.toString(),
        location: {
          type: "Point",
          coordinates: [i/1000, i/1000]
        }
      });
    }, 3000);
  });
}
Run Code Online (Sandbox Code Playgroud)

我在启动应用程序并打开浏览器后立即看到的内容:数字从x数组中逐个显示在屏幕上.每次新号码到达时,它都会出现在正确的位置,保持序列始终排序.

你的意思是'$ near reactive sorting'吗?