Please refer to this issue Here
I have same issue except i am not providing any geo data.
My Model's geo data implementation portion below
startLocation: {
// GeoJSON
type: {
type: String,
default: 'Point',
enum: ['Point']
},
coordinates: [Number],
address: String,
description: String
},
locations: [
{
type: {
type: String,
default: 'Point',
enum: ['Point']
},
coordinates: [Number],
address: String,
description: String,
day: Number
}
]
Same Request Body for each case below
{
"name": "The Test Tourxx",
"duration": 1,
"maxGroupSize": 1,
"difficulty": "medium",
"price": 501,
"summary": "Nothing exciting here man!",
"imageCover": "tour-3-cover.jpg",
"ratingsAverage": 4,
"guides": ["5e85e24bd1b3f918dc07bb3d", "5e85e262d1b3f918dc07bb3e"]
}
Response when connected local MongoDB below
{
"status": "error",
"error": {
"driver": true,
"name": "MongoError",
"index": 0,
"code": 16755,
"errmsg": "Can't extract geo keys: { _id: ObjectId('5e85fc64a4031f1734b55515'), startLocation: { type: \"Point\", coordinates: [] }, ratingsAverage: 4, ratingsQuantity: 0, rating: 4.5, images: [], createdAt: new Date(1585839200315), startDates: [], secretTour: false, guides: [ ObjectId('5e85e24bd1b3f918dc07bb3d'), ObjectId('5e85e262d1b3f918dc07bb3e') ], name: \"The Test Tourxx\", duration: 1, maxGroupSize: 1, difficulty: \"medium\", price: 501, summary: \"Nothing exciting here man!\", imageCover: \"tour-3-cover.jpg\", locations: [], slug: \"the-test-tourxx\", __v: 0 } Point must only contain numeric elements",
"statusCode": 500,
"status": "error"
},
"stack": "MongoError: Can't extract geo keys: { _id: ObjectId('5e85fc64a4031f1734b55515'), startLocation: { type: \"Point\", coordinates: [] }, ratingsAverage: 4, ratingsQuantity: 0, rating: 4.5, images: [], createdAt: new Date(1585839200315), startDates: [], secretTour: false, guides: [ ObjectId('5e85e24bd1b3f918dc07bb3d'), ObjectId('5e85e262d1b3f918dc07bb3e') ], name: \"The Test Tourxx\", duration: 1, maxGroupSize: 1, difficulty: \"medium\", price: 501, summary: \"Nothing exciting here man!\", imageCover: \"tour-3-cover.jpg\", locations: [], slug: \"the-test-tourxx\", __v: 0 } Point must only contain numeric elements\n at Function.create (C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\core\\error.js:43:12)\n at toError (C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\utils.js:149:22)\n at C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\operations\\common_functions.js:265:39\n at handler (C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\core\\sdam\\topology.js:913:24)\n at C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\cmap\\connection_pool.js:352:13\n at handleOperationResult (C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\core\\sdam\\server.js:487:5)\n at MessageStream.messageHandler (C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\cmap\\connection.js:270:5)\n at MessageStream.emit (events.js:311:20)\n at processIncomingData (C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\cmap\\message_stream.js:144:12)\n at MessageStream._write (C:\\Users\\Cody\\Desktop\\X-Files\\NodeJS\\4-natours\\node_modules\\mongodb\\lib\\cmap\\message_stream.js:42:5)\n at doWrite (_stream_writable.js:441:12)\n at writeOrBuffer (_stream_writable.js:425:5)\n at MessageStream.Writable.write (_stream_writable.js:316:11)\n at Socket.ondata (_stream_readable.js:714:22)\n at Socket.emit (events.js:311:20)\n at addChunk (_stream_readable.js:294:12)"
}
Response when connected to MongoDB Atlas(Removed unrelated potion) below
{
"status": "success",
"data": {
"tour": {
"startLocation": {
"type": "Point",
"coordinates": []
},
"ratingsAverage": 4,
"images": [],
"guides": [
"5e85e24bd1b3f918dc07bb3d",
"5e85e262d1b3f918dc07bb3e"
],
"_id": "5e85fb952754013728fc950c",
"name": "The Test Tourxx",
"duration": 1,
"maxGroupSize": 1,
"difficulty": "medium",
"price": 501,
"summary": "Nothing exciting here man!",
"imageCover": "tour-3-cover.jpg",
"locations": [],
"__v": 0,
}
}
}
As it can be seen local db throws error when creating empty array for "locations" but Atlas does it just fine.Please Help me identify the cause.
Mongoose: 5.9.7 Mockgoose: Not Used in the project MongoDB: 4.2.3(Local and Atlas both)
I know this is not a production code and you're working with small amounts of data, so drop your tours collection in compass and then run the script to import the data again. I have no idea why it works, but it works. I'm guessing it's some problem with old indexes? I don't know, It worked for me.
So if this doesn't work for you I guess you're just getting this error because you have startLocation as an 2dsphere index and maybe mongo is requiring you to input data there.
Try to create the tour below
{
"name": "The test tttttttt",
"duration": 4,
"maxGroupSize": 10,
"difficulty": "easy",
"price": 1,
"summary": "Exciting testt",
"imageCover": "mimimi.png",
"startLocation": {
"description": "Aspen, USA",
"type": "Point",
"coordinates": [-106.822318, 39.190872],
"address": "419 S Mill St, Aspen, CO 81611, USA"
}
}
All I did was add the startLocation object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.