Josette
Posts: 0
Joined: Mon Jun 08, 2015 10:59 pm

Geospatial queries with parameters returning entire collection

I am trying to find the closest public events within a specified distance. However, the results returned is the entire collection. See the query and database e.gs. below. The database has pointer columns. In this case there is only 1 event which is public and not private. So the result should be 1 record returned. Thanks for your help.

Image

Image

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Geospatial queries with parameters returning entire collection

Josette,

Since all geospatial data is recorded in the db as long / lat. ... either the data in your db is backwards or your query is right ?

Your data has longs of 28 / something and your query is looking near a long of -81.xxxx

The query and the data must both be long / lat ... instead of the Google lat / long ... unless I'm missing something...

You can also refer to the mongodb docs here :
https://docs.mongodb.com/manual/refer...

Also .... please make sure you have an index on this column ( your geo column) ... it's generally best practice to do this anyway for anything that you're going to Query on...

Happy Tuesday !

Bruce

Josette
Posts: 0
Joined: Mon Jun 08, 2015 10:59 pm

Geospatial queries with parameters returning entire collection

Bruce,

Thanks for your reply. I added a new column with lng/lat in the database to correspond with my query, but I got the same results as before, giving me all the objects in the collection.

Image

Image

I tried testing the query in the database, but I got the error below.

Image

Image

Any ideas what I might be doing wrong?

Thanks again for your help!

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Geospatial queries with parameters returning entire collection

Hi Josette,

Just checking - did you add an index on the new column - GeoLocation ??

Best,

Bruce

Josette
Posts: 0
Joined: Mon Jun 08, 2015 10:59 pm

Geospatial queries with parameters returning entire collection

Yes, but it didn't make a difference.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Geospatial queries with parameters returning entire collection

Also - per the docs here:

https://docs.mongodb.com/manual/refer...

the error code literally says "The specified options are in error or are incompatible with other options"...

so - specifically - you're sure you:

  1. Have an index?

  2. The column name - geolocation - that's kind of dicey - as that may be a reserved keyword - how about calling the column 'myLocation' or 'customerLocation' etc. ?

    I'll look at my syntax to ensure yours is workable as well....

    Best,

    Bruce

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Geospatial queries with parameters returning entire collection

Finally - it looks like - in your Javascript - which I assume is running in a server script - the statement which begins....

params = .....

should be:

params.criteria = .....

That's likely why - for the most part - if you correct the other issue (the column name issue ) - you are getting all of the records still - instead of the same error you are getting from the DB query.

Best,

Bruce

Josette
Posts: 0
Joined: Mon Jun 08, 2015 10:59 pm

Geospatial queries with parameters returning entire collection

Bruce,

I added the criteria property to the query and changed the object column to eventlocation as you suggested, but I got the Mongo Error 2.

Image

Image

Image

Also this is the index on the eventlocation column.

Image

Thanks again.

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

Geospatial queries with parameters returning entire collection

I'm not a fan of changing the name of a mongo db column ... as it retains the reference to the original name ... but don't know that's an issue as a matter of fact ... it would be better to create a new geopont column and copy the data there ... don't know if that's possible or will fix the issue for sure ...

So when you run server script ... you now get the error 2 when running the script ?

Josette
Posts: 0
Joined: Mon Jun 08, 2015 10:59 pm

Geospatial queries with parameters returning entire collection

Yes. I guess I can't use "criteria" in the query.

Return to “Issues”