Mongo geospatial index and Meteor

ε祈祈猫儿з 提交于 2019-12-03 11:53:37

问题


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 );

回答1:


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.




回答2:


Yes, I think you can.

On the server side, Meteor delegates find/update/.. into node-mongo-native call. You can take a look the code in packages/mongo-livedata/mongo_driver.js. And as I know, node-mongo-native supports geospatial index.



来源:https://stackoverflow.com/questions/11392566/mongo-geospatial-index-and-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!