0
我想通過Java在集合上運行$ near查詢。我不知道如何使用QeuryBuilder或BasicDbObject。通過Java代碼運行$ near查詢的正確方法是什麼?以下是我的文檔結構代碼。 「location」屬性將類型存儲爲點,座標存儲lat-long。我在這個集合上創建了一個2dsphere索引。
BasicDBObject doc = new BasicDBObject("attr1", nextLine[0])
.append("attr2", nextLine[1])
.append("edge-metro-code", nextLine[6])
.append("location", new BasicDBObject("type", "Point")
.append("coordinates",latLong))
.append("attr3", nextLine[9])
.append("attr4", nextLine[10])
值得指出的是,這代碼將在MongoDB版本2.4上工作,但不是2.2。 – Trisha
答案已更新。謝謝Trisha。 –