如何检索json元素的子数组?

时间:2016-07-04 11:21:53

标签: mongodb

以下是Employee类

public class Employee {

  public List<Department> departments;

  public List<Association> association;

  ....

}

数据在上述类的填充后成功插入。

MongoCollection.insert(实体);

通过Jongo检索Employee对象。它只返回员工而不是部门。

MongoCollection.findOne("{name: '"+name+"'}").as(Employee.class);

示例json文件。

{
    "_id": ObjectId("577a32894309be1f540cde3e"),
    "active": false,
    "departments": [
        {
            "_id": ObjectId("577a32894309be1f540cde3f"),
            "description": "sales",
            "name": "sales"
        }
    ],
    "email": "dinesh.rajul@gmail.com",
    "firstName": "dinesh",
    "lastName": "regjuk",
    "name": "admin",
    "password": "hsCIFfVifdOLG3vOUF7jF3x7bEiRCItm7FPiYAVdMW"
}

您能否帮我查询或获取json的子数组值(&#34;部门&#34;)?目前,当我们说employee.getDeparements()

时,列表返回null

由于

0 个答案:

没有答案