Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use $geoIntersects #13

Closed
vedi opened this issue Aug 2, 2016 · 1 comment
Closed

Can't use $geoIntersects #13

vedi opened this issue Aug 2, 2016 · 1 comment

Comments

@vedi
Copy link
Contributor

vedi commented Aug 2, 2016

I have:

"mongoose": "^4.4.12",

When I'm trying to do something like that:

MyModel.find({
  myLocField: {
    $geoIntersects: {
        $geometry: {
            type: 'Point' ,
            coordinates: [32.694865977875075, 35.293922424316406]
        }
    }
  }
});

I'm getting:

Unhandled rejection Error: Can't use $geoIntersects
    at SchemaType.castForQuery (/xxx/node_modules/mongoose/lib/schematype.js:875:13)
    at cast (/xxx/node_modules/mongoose/lib/cast.js:169:39)
    at Query.cast (/xxx/node_modules/mongoose/lib/query.js:2575:10)

I solved this, implementing:

GeoJSON.prototype.castForQuery = function ($cond, val) {
  if (arguments.length === 2) {
    return val;
  }
  return $cond;
}

If you think, it's good enough, you can put it to the code, and do the same for other classes.

There is a workaround, without changing the module:

  mongoose.SchemaType.prototype.$conditionalHandlers.$geoIntersects = ($cond, val) => {
    if (arguments.length === 2) {
      return val;
    }
    return $cond;
  };

But you'll need to do this for every additional condition you want to support, and you need to understand possible impact of this way.

@joshkopecek
Copy link
Contributor

As far as I know this has been resolved by PR #12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants