I have a set of documents from another developer and the latitude and longitude properties are separate fields (which is fine) but I need to do a geospatial query on them and the documentation supposedly do not allow for this so I'm creating a virtual property so that I can fetch them as an array like the docs say is preferred.
However, I'm running into an issue with it not being indexed as '2d' is there any way to have a virtual property indexed as 2d so I can run a proper geospatial query on it without rolling my own algorithm?
A simplified version of the code for my model is below with the virtual property underneath it.
var mongoose = require('mongoose');
// Create the schema.
var schema = new mongoose.Schema({
_id: {
lng: Number,
lat: Number
}
});
// Create virtual property so we can fetch as Mongoose prefers.
schema.virtual('location').get(function() {
var key = this._id;
return [key.lat, key.lng];
});
// Export the model.
module.exports = database.model('locations', schema);