Mongo geospatial index and Meteor
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.