const mongoose = require('mongoose'), Schema = mongoose.Schema; const schema = new Schema({ properties: { type: Schema.Types.Mixed }, geometry: { type: { type: String, required: true, enum: ['Point'], default: 'Point' }, coordinates: { type: [Number], index: '2dsphere' } }, byUser: { type: Schema.Types.ObjectId, ref: 'User', required: false } }); if (!schema.options.toObject) schema.options.toObject = {}; schema.options.toObject.transform = function (doc, ret/*, options*/) { ret = { _id: doc._id, name: doc.properties.name, type: doc.properties.type, agl: doc.properties.agl, // feet amsl: doc.properties.amsl, // feet coors: doc.geometry.coordinates }; return ret; } module.exports = mongoose.model('Obstacles', schema);