简体   繁体   English

MongoDB:使用Java驱动程序获取数组字段的元素

[英]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.

相关问题 MongoDB:如何使用Java驱动程序获取包含数组的所有元素? - MongoDB : how to get all elements that contain an array using Java Driver? MongoDB 如何使用 Java 驱动程序计算数组元素 - MongoDB how to count array elements with Java driver 如何使用 MongoDB java 驱动程序计算数组字段中匹配特定条件的元素并插入投影 - How to count elements matching certain condition in array field and insert into projection with MongoDB java driver MongoDB Java驱动程序阵列 - MongoDB Java Driver Array MongoDB:使用Java驱动程序在具有给定属性的数组中查找匹配元素 - Mongodb : find matching elements in an array with given attributes using java driver 如何使用java驱动程序将文档与mongodb中的现有数组元素进行匹配 - How to match a document with existing array elements in mongodb using java driver 返回列表匹配字段中的一个或多个元素的所有元素的查询 Java MongoDB Driver 3.7.1 - Query that returns all elements where one or more elements in List match field Java MongoDB Driver 3.7.1 MongoDB java驱动程序:获取受另一个字段限制的字段的所有唯一值 - MongoDB java driver: get all unique value of a field restricted by another field 检查Mongodb Java驱动程序中是否存在子字段 - Check for sub field existence in Mongodb java driver 按字段分组MongoDB Java驱动程序3+ - Group by Field MongoDB Java Driver 3+
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM