蒙哥地理空间指数和流星 [英] Mongo geospatial index and Meteor

查看:65
本文介绍了蒙哥地理空间指数和流星的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在流星建筑中使用mongodb地理空间索引.

Minimongo没有实现地理空间索引,但这是否意味着我们不能在服务器端使用此mongo功能?

例如,对于 todos 应用,如果我们在待办事项上使用位置信息,是否会可以做到:

// Publish complete set of lists to all clients.
Meteor.publish('todos', function (lon,lat) {
   return Todos.find({loc: {$near:[lon,lat]}}).limit(2);
});

在客户端:

Meteor.subscribe('todos', lon, lat );

解决方案

是的,您可以在Meteor中使用MongoDB地理空间索引,并且也可以在Meteor应用程序中创建该索引. /p>

-地理空间搜索

我正在使用下面的$within运算符,而不是上面提到的$near运算符,但这仍然适用:

Meteor.publish('places', function(box) {
    return Places.find({ loc : { $within : { $box : box }}});
});

提醒:此类地理查询仅在服务器上可用(当前).

-从流星内部创建地理空间索引(而不是在MongoDB shell中)

Places._ensureIndex({ loc : "2d" });

例如您可以在bootstrap.js中使用以上内容.

此外,您可能希望将ensureIndex放在Meteor.startup中,或者当您插入一些初始数据时.


警告:如此处,上述调用ensureIndex的方法是一种可替代的解决方法,因为它缺少正式的调用方式,因此请期待这可能会改变.

更新:现在反映了流星0.5.0中的更改,请参见下面的 @Dror 的评论

I am wondering if it is possible to use a mongodb geospatial index with Meteor architecture.

Minimongo does not implement geospatial indices, but does this mean that we cannot use this mongo feature on the server side?

For example, with the todos app, if we use location on the todo, will it be possible to do:

// Publish complete set of lists to all clients.
Meteor.publish('todos', function (lon,lat) {
   return Todos.find({loc: {$near:[lon,lat]}}).limit(2);
});

And on the client side :

Meteor.subscribe('todos', lon, lat );

解决方案

Yes, you can use the MongoDB geospatial index within Meteor, and you can create that index from within your Meteor app too.

- Geospatial Search

I'm using the $within operator below, as opposed to the $near operator mentioned above, but this still applies:

Meteor.publish('places', function(box) {
    return Places.find({ loc : { $within : { $box : box }}});
});

Reminder: These kinds of geo queries are only available on the server (currently).

- Creating a Geospatial Index from within Meteor (rather than in a MongoDB shell)

Places._ensureIndex({ loc : "2d" });

e.g. You could use the above in your bootstrap.js.

Also, you'll probably want to put your ensureIndex in Meteor.startup, or perhaps when you're inserting some initial data.


Warning: As mentioned here, the above method of calling ensureIndex is a work around for want of an official way to call it, so please expect that this might change.

Update: now reflects changes in Meteor 0.5.0, see @Dror's comment below.

这篇关于蒙哥地理空间指数和流星的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆