How can I run this mongodb command geonear in Java
db.runCommand ({ geoNear : “mycollection”, near : [
-121.97679901123047,37.557369232177734], spherical : true, maxDistance : 50 / 3959 /* to radians */ , query : { $or : [
{“myuserid” : “att”},{“_id”:{$in:
[ObjectId(“4fda8fbbe7e96e2d775595d”)] }}] } } );
I am trying this in java using Commandresult but getting error.
This is what I did so far and getting Null pointer exception although the command is printing right. I am new to java and database person.
BasicDBObject myCmd = new BasicDBObject();
myCmd.append("geoNear", "mycollection");
double[] loc = {-121.97679901123047,37.557369232177734};
myCmd.append("near", loc);
myCmd.append("spherical", true);
myCmd.append("maxDistance", (double)50 / 3959 );
System.out.println(myCmd);
CommandResult myResults = db.command(myCmd);
System.out.println(myResults.toString());
Thanks in advance.
I was able to figure out my problem. Not connected to the right database. Thanks for all your help. Geo query is working fine now. Thanks.