1

I'm new to Java Mongo DB. I have to Store a huge amount of data. I'm planning to store it in a collection. I have few doubt in that.

  1. How to access the elements of a collection? (for example: Access first 5 elements or 10th to 15th elements)

  2. Is it possible to access nth element using indexes? (I hope indexes is only for sorting the collection asc or desc order)

  3. To store huge data using collection is enough?

1 Answer 1

1

1 Ans>An iterator over database results. Doing a find() query on a collection returns a DBCursor thus

 DBCursor cursor = collection.find( query );
 if( cursor.hasNext() )
     DBObject obj = cursor.next();

For example, to get an array of the 10-15th elements of a cursor, use

 List obj = collection.find( query ).skip( 10 ).limit( 5 ).toArray();

2 Ans> An index in MongoDB in the same sort of situations where you would have wanted an index in MySQL.

3 Ans> Yes

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.