繁体   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