/node_modules/mongoose/examples/geospatial/geoJSONSchema.js

https://bitbucket.org/coleman333/smartsite · JavaScript · 22 lines · 12 code · 3 blank · 7 comment · 0 complexity · 8098b2b7c50c789a1516a8cc39c3b7d6 MD5 · raw file

  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. };