Results 1 to 5 of 5

Thread: mongodb marshalling/unmarshalling

  1. #1
    Join Date
    Dec 2012
    Posts
    9

    Default mongodb marshalling/unmarshalling

    Hi. I'am use spring data for mongodb. I have more documents in one collection. Time of select above 20 000 (30 000 - 40 000) records = 7+ seconds. Indexes are built. This is a problem in marshalling?

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Do you have a test case that we could look at? You might wanna try reading the documents into plain DBObjects and compare the results.

  3. #3
    Join Date
    Dec 2012
    Posts
    9

    Default

    I have done test case.

    #1
    Code:
            DBCollection collection = mongoOperations.getCollection(table);
            BasicDBObject query2 = new BasicDBObject("login", login);
            current = System.currentTimeMillis();
            DBCursor cursor = collection.find(query2);
    
            count = cursor.count();
    
            logger.info("######## Count: {}, Time: {} ########", count, (System.currentTimeMillis() - current));
    #2
    Code:
            current = System.currentTimeMillis();
            List<Action> result =  mongoOperations.find(query, Action.class, table);
            logger.info("Time : {} ", (System.currentTimeMillis() - current));
    Results:

    #1
    Code:
    ######## Count: 30847, Time: 35 ########
    #2
    Code:
    Time : 7448

  4. #4
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    483

    Default

    Well, that's not a fair comparison by any means. In #1 you basically haven't read any data at all. So you would have to iterate the cursor and actually create Action objects from the DBObjects returned. Especially the first step will actually cause the data being read.

    Beyond that I'd argue that it is not much different to reading 30k table rows of a relational database into domain objects VS. simply reading them into a ResultSet. It highly depends on what you actually want to do with the data and whether it really makes sense to read all objects at once.

    Long story short, it would be cool if you could report back what times you get if you actually read and marshal data manually.

  5. #5
    Join Date
    Dec 2012
    Posts
    9

    Default

    Yes, you are right.

    How to calculate count of documents in collection and do not load their in memory ?

    Code:
    Query query = new Query();
    query.addCriteria(Criteria.where("login").is(login));
    long count = mongoOperations.count(query, table);
    May be this ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •