google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

GeoSpatial Near Criteria Not working with radius #275

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia/Driver/MongoDB)
0.99
Please include a stack trace below:
When using the near criteria with radius, and the spherical value a false, the 
query is not generated properly.
egs:
  Query<Job> query = getDatastore().find(Job.class)
                                .field("geoLocation")
                                .near( 42.08563,-87.99822, 2);
The toString on the above query is :{ "GEO_LOCATION" : { "$near" : [ 42.08563 , 
-87.99822]}}
The actual query should have been: { "GEO_LOCATION" : { "$near" : [ 42.08563 , 
-87.99822], "$maxDistance": 2}}

Also, with spherical option to true: then the query generated is not compiled.
Query<Job> query = getDatastore().find(Job.class)
                                .field("geoLocation")
                                .near( 42.08563,-87.99822, true, 2);
{ "GEO_LOCATION" : { "$near" : [ 42.08563 , -87.99822] , "$maxDistance" : 0.5 , 
"$sphere" : true}}
When, I execute that, I get the following stack trace:

com.mongodb.MongoException: invalid operator: $sphere
    at com.mongodb.MongoException.parse(MongoException.java:82)
    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:302)
    at com.mongodb.DBCursor._check(DBCursor.java:354)
    at com.mongodb.DBCursor._hasNext(DBCursor.java:484)
    at com.mongodb.DBCursor.hasNext(DBCursor.java:509)
    at com.google.code.morphia.query.MorphiaIterator.hasNext(MorphiaIterator.java:40)
    at com.google.code.morphia.query.QueryImpl.asList(QueryImpl.java:234)
    at com.spotj.dao.impl.JobDAOImpl.findJobsNearALocation(JobDAOImpl.java:52)
    at com.spotj.service.impl.JobServiceImpl.findJobsNearALocation(JobServiceImpl.java:51)
    at com.spotj.service.JobServiceImplTests.testFindByRadius(JobServiceImplTests.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Original issue reported on code.google.com by ykatt...@gmail.com on 10 May 2011 at 3:46

GoogleCodeExporter commented 9 years ago
Sorry, i did not give full details of my environment:
Morphia : 0.99
Mongo Driver:2.5.3
MongoDB Version:1.8.1

Original comment by ykatt...@gmail.com on 10 May 2011 at 3:48

GoogleCodeExporter commented 9 years ago
i have the same question . who can resolve it
  my environment:
  Morphia : 0.99
Mongo Driver:2.3.0
MongoDB Version:1.8.2

Original comment by jonerxqj...@gmail.com on 30 Mar 2012 at 9:52

GoogleCodeExporter commented 9 years ago
I have the same error.
Morphia: Morphia : 0.99
Mongo Java Driver: 2.7.3
MongoDB Version: 2.0.2

Original comment by mar...@tipgain.com on 30 May 2012 at 5:25

GoogleCodeExporter commented 9 years ago
I have the same error.

Morphia 0.99
Mongo Java driver 2.7.3

Please fix this!

Original comment by vir...@gmail.com on 4 Jan 2013 at 7:31