Page 1 of 2

Geospatial queries with parameters returning entire collection

Posted: Tue Jul 11, 2017 10:59 pm
by Josette

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


Geospatial queries with parameters returning entire collection

Posted: Wed Jul 12, 2017 2:12 am
by Bruce Stuart

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


Geospatial queries with parameters returning entire collection

Posted: Thu Jul 13, 2017 1:54 am
by Josette

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!


Geospatial queries with parameters returning entire collection

Posted: Thu Jul 13, 2017 2:05 am
by Bruce Stuart

Hi Josette,

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

Best,

Bruce


Geospatial queries with parameters returning entire collection

Posted: Thu Jul 13, 2017 2:07 am
by Josette

Yes, but it didn't make a difference.


Geospatial queries with parameters returning entire collection

Posted: Thu Jul 13, 2017 2:09 am
by Bruce Stuart

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


Geospatial queries with parameters returning entire collection

Posted: Thu Jul 13, 2017 2:14 am
by Bruce Stuart

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


Geospatial queries with parameters returning entire collection

Posted: Thu Jul 13, 2017 2:37 am
by Josette

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.


Geospatial queries with parameters returning entire collection

Posted: Thu Jul 13, 2017 2:43 am
by Bruce Stuart

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 ?


Geospatial queries with parameters returning entire collection

Posted: Thu Jul 13, 2017 2:54 am
by Josette

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