Saving geo coords with Mongoose

Saving geo coords with Mongoose
0

#1

Hey everyone, I have a question related to Mongoose and saving geo coordinates. I am trying to update documents in a collection with geo coordinates I am getting from an API. I am getting the coordinates just fine, but when I try to update individual documents, I get an error stating:

"'Can\'t extract geo keys: { _id: ObjectId(\'59fce3cb295c2d23e9f966ca\') ...}   can\'t project geometry into spherical CRS: [ 37.9196393521182, -122.302392011646 ]',
  driver: true,
  index: 0,
  code: 16755,"

My schema looks like this:

const meetingSchema = new Schema({
geo: { //lng then lat
        type: [Number],
        index: '2dsphere',
        required: false
    }

});

My update function looks like this:

Meeting.update(
                    {_id: _id},
                    {$set: {geo: coordArr }},//coordArr is just an array with 2 values in it
                    (err, data) => {
                        if(err){
                            console.log(err);
                        } else {
                            console.log(data.geo);
                        }
                    }
                );

I am guessing the coordArr needs to be in a different format, but I have been searching and not finding exactly what the format should be. Any help would be appreciated. Thank you!


#2

Found the problem, I was pushing coordinates to the array in the wrong order.