0

I have a file user-model that defines the Mongoose schema for 'User' and is as follows :

const mongoose = require('mongoose')
const Schema = mongoose.Schema

const PointSchema = new mongoose.Schema({
  type: {
    type: String,
    enum: ['Point'],
    required: true
  },
  coordinates: {
    type: [Number],
    required: true
  }
});


const User = new Schema(
    {
        userName: { type: String },
        firstName: { type: String },
        lastName: { type: String},
        primaryContact: { type: String },
        secondaryContact: { type: String },
        emergencyContact : { type: String },
        location: { type: PointSchema }, //should store the user's location coordinates
    },
    { timestamps: true },
)

module.exports = mongoose.model('users', User)

Is this the correct way to define the location attribute in the User schema? Also is the definition for PointSchema logically correct?

Also I want to be able to insert a single document on MongoDB's Atlas that follows the above schema . Atlas offers a range of datatypes, however I'm not sure which one to use to store a location's coordinates. Could someone please point me in the right direction? Thank you.

sublime_archon
  • 161
  • 2
  • 11
  • Does this answer your question? [Location in mongoose, mongoDB](https://stackoverflow.com/questions/27218389/location-in-mongoose-mongodb) – whoami - fakeFaceTrueSoul Dec 09 '19 at 17:59
  • Or try this : https://stackoverflow.com/questions/15274834/how-to-store-geospatial-information-in-mongodb, schema looks ok, this question looks more of review thing, Please try and post if you get an error.. – whoami - fakeFaceTrueSoul Dec 09 '19 at 18:00

0 Answers0