geoJSONSchema.js 613 B

12345678910111213141516171819202122
  1. // import the necessary modules
  2. var mongoose = require('../../lib');
  3. var Schema = mongoose.Schema;
  4. // create an export function to encapsulate the model creation
  5. module.exports = function() {
  6. // define schema
  7. // NOTE : This object must conform *precisely* to the geoJSON specification
  8. // you cannot embed a geoJSON doc inside a model or anything like that- IT
  9. // MUST BE VANILLA
  10. var LocationObject = new Schema({
  11. loc: {
  12. type: {type: String},
  13. coordinates: []
  14. }
  15. });
  16. // define the index
  17. LocationObject.index({loc: '2dsphere'});
  18. mongoose.model('Location', LocationObject);
  19. };