Not sending not required geo coordinates gives MongoServerError: Can’t extract geo keys

Hi.

I have this schema:

new mongoose.Schema({
	name: {
        type: String,
        required: true
    },
    location: {
        type: {
            type: String,
            default: 'Point',
            enum: ['Point']
        },
        coordinates: [Number],
        address: String,
        description: String
    }

})

Location isn’t required, but if I’m sending only a name in my request, I’m getting this error: MongoServerError: Can't extract geo keys:

How do I make location not required?
Thanks!

Figured it out!
In case anyone faces the same error: make sure you don’t have an index on this field, it makes the field required.

1 Like

Thanks Brother You saved me

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.