Google Groups

Re: [mongodb-user] Re: Mongo db spatial query support with java


何健 Apr 17, 2012 1:58 AM
Posted in group: mongodb-user
I'm afraid inserting in this way via Java wouldn't work. It will be treated as a string value instead of long/lat value.

"50,50" can be put into an array.

2012/4/17 Ronnie <anku...@tcs.com>
Thanks HJ,

Got your point.

My concern is that :

I can use the mongo shell to insert spatial data like :

>db.places.insert({loc : [50,50]})

I am using the following code base through java :

BasicDBObject doc = new BasicDBObject();
               //Location loctn = new Location();
               //System.out.println(sensorlocation +" "
+loctn.getMongoCompatiblePositionAttr(sensorlocation));
               doc.put("loc", "50,50");
       coll.insert(doc);

Here "50,50" is the lat/long data. I have doubt that inserting like
this will not provide correct data at the time of spatial query.

I wanna avoid spring-mongo api.Could you you please guide on this?

Thanks in advance.


On Apr 17, 1:32 pm, "H.J" <shiyi...@gmail.com> wrote:
> use same sample data in this blog:http://blog.codecentric.de/en/2012/02/spring-data-mongodb-geospatial-...
>
> In my opinion, it is same as other queries.
>
>  DBCollection loc = db.getCollection("location");
>  BasicDBList v1 = new BasicDBList();
>  v1.add(0);
>  v1.add(0);
>  // db.location.find( {position: { $near: [0,0], $maxDistance: 0.75  } } )
>  BasicDBObject query = new BasicDBObject();
>  query.put("position",
> BasicDBObjectBuilder.start().append("$near",v1).append("$maxDistance",
> 0.75).get());
>  DBCursor cursor1 = loc.find(query);
>
> 2012/4/17 Ronnie <ankur...@tcs.com>
>
>
>
>
>
>
>
>
>
> > Hi All,
> > I have got some answers regarding "Mongo db spatial query support with
> > java" , from Spring Data - MongoDB.
>
> > However I do not know spring.
>
> > Could any one provide some other way out.?
>
> > Thanks and Regards
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mongodb-user...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/mongodb-user?hl=en.
>
> --
> 尽人事,听天命!

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.




--
尽人事,听天命!