日期:2014-05-16  浏览次数:20428 次

mongodb java ensureIndex写法,生成2d坐标与查询

转自:http://blog.goyiyo.com/archives/1984

?

使用的是 mongo-java-driver 2.11.4

maven资源包下载方法:

<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.11.4</version>
</dependency>

Java代码处理:

BasicDBObject index = new BasicDBObject("gps", "2d");
coll.ensureIndex(index);

?

查询条件的写法
BasicDBObject object = new BasicDBObject("gps", new BasicDBObject("$near", Arrays.asList(42.424110930486, 128.12194988221)).append("$maxDistance", 3/111.12));

?

mongo对象的获取不支持spring