Now i tried with a different db :Refer to the script below:
> db.testCol.ensureIndex({ foi_geom : "2d" })
> db.testCol.find({"foi_geom":{"$within":{"$box":box}}})
{ "_id" : ObjectId("4fa0d6a21087b08a3095ad79"), "foi_geom" : [ 8.2,
53.2 ] }
> db.testCol.drop()
true
> db.testCol.insert({"foi_geom":[8,53]})
> db.testCol.ensureIndex({ foi_geom : "2d" })
> box = [[8.1,50.5],[9.1,54.5]]
[ [ 8.1, 50.5 ], [ 9.1, 54.5 ] ]
> db.testCol.find({"foi_geom":{"$within":{"$box":box}}})
> box = [[7,50],[9,54]]
[ [ 7, 50 ], [ 9, 54 ] ]
> db.testCol.find({"foi_geom":{"$within":{"$box":box}}})
{ "_id" : ObjectId("4fa0d7481087b08a3095ad7b"), "foi_geom" : [ 8,
53 ] }
I again got data.
Then I tried the following java code :This time no exception but got
no data as well:
Mongo m = null;
try {
m = new Mongo("localhost", 27017);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MongoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DB db = m.getDB("testdatabase");
System.out.println(db);
DBCollection coll = db.getCollection("testCol");
System.out.println(coll);
//myPolygon = [[0,0], [0,4], [2,6], [4,4], [4,0]];//
8.1,9.5,55.1,54.5//8.3 , 53.5
ArrayList<ArrayList<Integer>> mybox = new
ArrayList<ArrayList<Integer>>();
ArrayList<Integer> point1 = new ArrayList<Integer>();
point1.add(7);
point1.add(50);
ArrayList<Integer> point2 = new ArrayList<Integer>();
point2.add(9);
point2.add(54);
mybox.add(point1);
mybox.add(point2);
BasicDBObject myQuery = new BasicDBObject();
BasicDBObject withinQuery = new BasicDBObject();
withinQuery.append("$within", new BasicDBObject("$box",mybox));
myQuery.append("foi_geom", withinQuery);//"foi_geom"
//for (String s : colls) {
DBCursor c = coll.find(myQuery);
System.out.println(myQuery);
while(c.hasNext()){
System.out.println(c.next().toString());
}
Can put some light on it?
Thanks in advance.This has become really annoying.
On May 2, 11:36 am, "H.J" <
shiyi...@gmail.com> wrote:
> I think it's better to try each collection one by one, maybe some of
> them don't fulfill geo searching.
>
> 2012/5/2Ronnie<
ankur...@tcs.com>: