0

JAVA ドライバーを使用しており、ドキュメントの検索を実行しています。返されるドキュメントのタイプは Document です。

コードから、正しく出力される String type('name') を確認できます。時間の配列を文字列として表示することもできます。

私が探しているのは、値8になる時間[1] [2]を選択する配列から特定の要素を取得することです.

JSONObjectに変換せずに、Documentタイプでこの操作を直接実行しようとしています。

これは可能ですか?

{
"name": "Temp1", "hours": [ [ 0, 1, 2, 3, 4, 5 ], [ 6, 7, 8, 9, 10, 11 ],[ 12, 13, 14, 15 , 16, 17 ] ]
{

FindIterable<Document> iterable = collection.find(and(eq("day", day),eq("month", month),eq("year", year),eq("name", java.util.regex.Pattern.compile("Temp"))));         
iterable.forEach(new Block<Document>() {
    @Override
        public void apply(final Document document) {
            //System.out.println(document.toJson());
            System.out.println("Name: "+document.getString("name"));                    
            System.out.println("Hours[]: "+document.get("hours"));
        }
  }
4

1 に答える 1

0

次のような DBList オブジェクトにキャストする必要があります。

(BasicDBList) document.get("hours");

その後、通常のリストと同じようにリストを反復処理できます!

于 2016-01-14T08:00:20.957 に答える