Vignesh
Vignesh

Reputation: 2325

How to access array field from query result in MongoDB

I got a JSON object in Cursor as follows

{
        "field1": "val1",
        "field2": [
            {
                "field3": "val3"
            },
            {
                "field4": "val4"
            }
        ]
}  

I'm able to access the feild1 and its value. How to access field3 and its value?
I tried the following code but not working

System.out.println(cursor.next().get("field2.field3"));  

Getting null as output.

Upvotes: 0

Views: 315

Answers (1)

Ppm
Ppm

Reputation: 162

Try this.Hope this will help.

Upvotes: 1

Related Questions