[英]MongoDB: get elements of array field with java driver
I have the following BasicDBObject object: 我有以下BasicDBObject对象:
{
"name":"joe"
"jobs":
[
{"adress" : "adress1"
"years": 2},
{"adress" : "adress2"
"years" :3}
}
I want to get the "jobs" field and enter the "adress" field and "years" field 我想获取“职位”字段,然后输入“地址”字段和“年”字段
I traying somethink like ....object.get("jobs") ....get "adress" and " years" fields. 我盘点诸如.... object.get(“ jobs”).... get“ adress”和“ years”字段之类的东西。
please help 请帮忙
Use BasicDBList to read the array inside the "jobs". 使用BasicDBList读取“作业”中的数组。 Then iterate over the array to get each object.
然后遍历数组以获取每个对象。
BasicDBList jobsArr = (BasicDBList) object.get("jobs");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.