0

How to get all the document under array in mongodb java. My Database is as below. Want to retrieve all the data under array 198_168_1_134.

enter image description here

below is some of What i tried,

eventlist.find(new BasicDBObject("$match","192_168_10_17"))
eventlist.find(new BasicDBObject("$elemMatch","192_168_10_17"))
eventlist.find(null, new BasicDBObject("$192_168_10_17", 1))
2
  • 1
    How can we copy and paste code from an image so that we can help you by reproducing the same problem on our PCs? Commented Apr 21, 2015 at 11:52
  • @chirdam it's just for reference that how database is look a like. Commented Apr 21, 2015 at 11:56

2 Answers 2

1

You have two options:

  • using .find() with cherry-picking which document you have to have fetched.
  • using the aggregation framework by projecting the documents.

By using .find() , you can do:

db.collection.find({}, { 192_168_10_17 : 1 })

By using the aggregation framework, you can do:

db.collection.aggregate( { $project : { 192_168_10_17 : 1 } } )

which will fetch only the 192_168_10_17 document data.

Of course, in order to get this working in Java, you have to translate these queries to a corresponding chain of BasicDBObject instances.

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

1 Comment

Should be working. Try it out again. Anyway, I'm glad I helped you. :)\
0

By using mongo java driver you can do this by following query -

eventlist.find(new BasicDBObject(), new BasicDBObject("198_168_1_134", 1)) 

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.