Mongodb获取附近的人

double[] loc = new double[2];//坐标[longitude, latitude]
loc[0] = 114d;//longitude
loc[1] = 118d;// latitude
DBObject near = new BasicDBObject();
near.put("$near", loc);//表示near查询,单位是“度”
near.put("$maxDistance",  );//最大距离
near.put("$minDistance", );//最小距离
DBObject p = new BasicDBObject();
p.put(“loc”, near);//坐标在collection中的字段名,你这是loc
DBCollection dbCollection = positionDB.getCollection(“places”);//获取数据库里的collection,你这是places
DBCursor dbCursor = dbCollection.find(dbObject).limit(20);//查找20个

你可能感兴趣的:(nosql)