Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:24:54+00:00 2026-06-13T23:24:54+00:00

I store the system log in mongodb with building index according to ‘time’ field.

  • 0

I store the system log in mongodb with building index according to ‘time’ field. There are about 190k logs in mongodb now.
When I try to get all logs using DBCollection.find() method in Java, it spends almost 10 seconds for traversing all the documents in the collection. I think there might be something I have missed that cause the poor performance?

Here is the code I used:

mongo = new Mongo();
DB db = mongo.getDB("Log");
DBCollection coll = db.getCollection("SystemLog");
int count = 0;

long findStart = Calendar.getInstance().getTimeInMillis();

// Sort by time.
BasicDBObject queryObj = new BasicDBObject();
queryObj.put("time", -1);

DBCursor cursor = coll.find().sort(queryObj);
while(cursor.hasNext()) {
    DBObject obj = cursor.next();
    // Do something
    ++count;
}
long findEnd = Calendar.getInstance().getTimeInMillis();
System.out.println("Time for traversing all system logs (" + count + "):\t" + (findEnd-findStart) + "ms.");

And the printed result is:

Time for traversing all system log (194309):    10496ms.

I have tried it several times. It seems no difference between running one time or multiple times. Though I have also tried to remove sort() and just find all the logs out from mongodb. It takes about 6 seconds for traversing all the documents. The time is still kind of unacceptable for my requirement. Is there any implementation tips that can speed up the traversing work?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:24:55+00:00Added an answer on June 13, 2026 at 11:24 pm

    Do you really need to traverse all documents ? In the code above it looks like you are just bringing into memory each object, one by one.

    1. The index on ‘time’ field should be constructed as ‘descending’ since you are sorting like that.
    2. If the index is compound (has more fields in the index, not just ‘time’) make sure you also add an index just with ‘time’. Also, when you will add a filter to that query, make sure the ‘time’ field is added last in the index and descending.
    3. The performance is not that bad, considering you are reading 190k objects one by one.

    (please note that my experience with mongodb does Not involve working with the Java driver)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a system that collects real-time Apache log data from about 90-100 Web
We have a system were we would like to store about 100M documents. We
I am designing a logging system that will store its log entries in RavenDB,
I'm making system like client-server. There's two possibilities: to log in as user or
I am planning to build a cassandra store system and also I need a
I have a problem with the system function. I want to store the system
Android System has a builtin certificate Store. The certificates from this store are for
I am using System.Data.SQLite to store my program's data and settings (in a WPF
I am creating a system that will store objects in an SQLite Database. I
I'm developing a system which needs to store videos in the form: /path/to/video/<md5 of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.