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.