GeoObjects Schema

一種通用模式,可用於處理點,線字串和多邊形等地理物件。這兩種MongooseMongoDB 的支援 GeoJSON 的

Node / Express 中的用法示例 :

var mongoose = require('mongoose');
var Schema   = mongoose.Schema;

// Creates a GeoObject Schema.
var myGeo= new Schema({
                        name: { type: String },
                        geo : {
                                type : {
                                         type: String, 
                                         enum: ['Point', 'LineString', 'Polygon']
                                },
                                coordinates : Array
                         }
});

//2dsphere index on geo field to work with geoSpatial queries
myGeo.index({geo : '2dsphere'});
module.exports = mongoose.model('myGeo', myGeo);