2017-02-21 94 views
0

試圖找到從蒙戈DB收藏使用Java代碼的MongoDB:從蒙戈集合

Bson newValue = new Document("_id", true); 
    List<Document> collections = collection.find(newValue).into(new ArrayList<Document>()); 

特定的列值獲得特定的列值,但它returs什麼。

當我在mongo shell中使用以下命令嘗試時,它按照預期返回數據。

db.weather.find({},{_id:true}).pretty(). 

我不知道如何設置{}在Java代碼下面

List<Document> collections = collection.find(newValue).into(new ArrayList<Document>()); 

回答

0

申請特定列投影,

  Document query = new Document(); 

     Document projection = new Document(); 
     projection.append("_id", 1); 

     collection.find(query).projection(projection);