Reputation: 11
I created model, and i want to save it to my mongoDB Compass.
const BootcampSchema = new mongoose.Schema({
location:{
// GeoJSON Point
type: {
type: String,
enum: ['Point'],
required: true
},
coordinates: {
type: [Number],
required: true,
index: '2dsphere',
sparse: true,
},
formattedAddress: String,
street: String,
city: String,
state: String,
zipcode: String,
country: String
});
Upvotes: 0
Views: 330
Reputation: 91
All you have to remove or change required to false code
location:{
// GeoJSON Point
type: {
type: String,
enum: ['Point'],
required: false
},
coordinates: {
type: [Number],
required: false,
index: '2dsphere',
sparse: true,
},
formattedAddress: String,
street: String,
city: String,
state: String,
zipcode: String,
country: String
});
Upvotes: 1
Reputation: 13
When saving a Bootcamp document, you have to ensure that the location field has a type property. It should look something like this:
{
...,
location: {
type: ...,
coordinates: ...
}
...
}
Upvotes: 0