簡體   English   中英

如何使用 Java 從 MongoDB 中的所有文檔中獲取相同鍵的值?

[英]How do I get values of same key from all documents in MongoDB using Java?

我是 mongodb 的新手。 這是我的 Mongodb 文檔,我只想要名稱值。

{
    "_id" : ObjectId("5da527f784a58d78fcd0b177"),
    "name" : "Jabed",
    "email" : "jabed@gmail.com",
    "Sex" : "male",
    "age" : "19",
    "address" : "Kochukhet, Dhaka",
    "Contct" : "01797259329"
}

{
    "_id" : ObjectId("5da6f415f2bdee4b90cf41d0"),
    "name" : "Bulbul Gulzer Deb",
    "email" : "gulzer.deb@gmail.com",
    "Sex" : "male",
    "age" : "19",
    "address" : "Narinda, Dhaka",
    "Contct" : "01756223666"
}

{
    "_id" : ObjectId("5dd771907607c3e12d9183d7"),
    "name" : "Aniruddha Dey",
    "email" : "aniruddha.dey@gmail.com",
    "Sex" : "male",
    "age" : "14",
    "address" : "Narinda, Dhaka",
    "Contct" : "01745706020"
}

預計 output 將

Jabed
Bulbul Gulzer Deb
Aniruddha Dey

使用投影:

db.yourdocument.find( {}, { name: 1, _id: 0 } )

可以在此處找到對投影字段的更多控制

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM