0

CSV の行を GeoJSON オブジェクトに変換したい。私はCSVReaderを使用しています。したがって、 nextLine[] にはすべての分離されたトークンがあります。さまざまな属性が格納されている BasicDBObject を作成したいと考えています。私は次の方法でそれをやっています。

new BasicDBObject("attribute1",nextLine[0]).append("attribute2",nextLine[1])

私が達成したいのは、MongoDB { attribute1: name attribute2: address location:{ type : "Point" , coordinate : [lat, long] } attrribute3: phonenumber } でこのようなドキュメントを作成することです BasicDBObject を使用してこれを行うにはどうすればよいですか?enter code here

4

2 に答える 2

0

違う方法でやった

double latLong[] = new double[]{10.0, 30.0};
BasicDBObject doc = new BasicDBObject("attr1",nextLine[0])
         .append("attr2", nextLine[1]
    .append("location",new BasicDBObject("type","Point")
.append("coordinates",latLong)) 
    .append("attr3", nextLine[3])

これも希望どおりに機能します

于 2013-07-02T21:00:39.297 に答える
0

これを行う最も簡単な方法は、DBObject を構築するためのユーティリティ クラスである BasicDBObjectBuilder を使用することです。あなたはそのようなことをすることができます:

BasicDBObject toInsert = BasicDBObjectBuilder.start()
    .add("attribute1",nextLine[0])
    .add("attribute2",nextLine[1])
    .add(" attrribute3",nextLine[2])
    .push("location")
        .add("type", "Point")
        .add("coordinates", new double[] { nextLine[3], nextLine[4] })
    .pop()
    .get()
于 2013-07-02T11:05:48.600 に答える