Reputation: 1833
I were using Mongoose 4.x and everything was fine. Soon I updated it to Mongoose 5.0.1, I started getting this error
/Users/me/ExampleCode/example-backend/example-backend-admin/example-backend-admin-places/node_modules/mongoose/lib/utils.js:417
throw err;
^
MongoError: unknown string alias for $type: 2dsphere
at Function.MongoError.create (/Users/me/ExampleCode/example-backend/example-backend-admin/example-backend-admin-places/node_modules/mongodb-core/lib/error.js:45:10)
at /Users/me/ExampleCode/example-backend/example-backend-admin/example-backend-admin-places/node_modules/mongodb/lib/db.js:1103:54
at /Users/me/ExampleCode/example-backend/example-backend-admin/example-backend-admin-places/node_modules/mongodb-core/lib/connection/pool.js:541:18
at process._tickCallback (internal/process/next_tick.js:150:11)
Process finished with exit code 1
I never touched the schema for a long while, the only change was updating mongoose, so I'm sure it's where the problem is.
Here's the relevant part in the Mongoose Schema
geometry: {type: String, trim: true, index: {unique: false, name: 'geometry', partialFilterExpression: {geometry: {$type: '2dsphere'}}}},
I'm drowning .... save me ....
Upvotes: 1
Views: 630
Reputation: 182
As refer to docs for MongoDB - partial index fields, the $type is refer to BSON types, which are existed in Mongo and nor your own type, so my point is that you need to change the query for that like
partialFilterExpression: {geometry: {$eq: '2dsphere'}}
I'm not sure how it could been working previously
Upvotes: 0