0
  db.Profile_Pic.find().pretty();
{
    "_id" : ObjectId("51cc08b505ca33ead716df9b"),
    "profile_id" : 101,
    "profile_pic" : [
        "1.jpg"
    ],
    "product_img" : [
        "1.jpg",
        "2.jpg"
    ],
    "company_logo" : [
        "1.jpg",
        "2.jpg"
    ]
}

I want to select individual elements from "product_img" array. I have written following code in java,`

While(f.hasNext())
{
String t=f.next().get("product_img").toString();
}

Above code return me the whole array of "product_img".

[ "1.jpg" , "2.jpg"]

I want to fetch individual element from "product_img". `

1
  • 2
    try BasicDBList list = (BasicDBList) f.next().get("product_img"); and then check the values in the list Commented Jun 27, 2013 at 11:14

1 Answer 1

1

Ok, since it works, I will transform my comment in an answer :)

You can try

BasicDBList list = (BasicDBList) f.next().get("product_img"); 

and then check the values in the list.

Here are the JavaDocs: http://api.mongodb.org/java/current/com/mongodb/BasicDBList.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.