1

I want to store large objects in mongoDB but I'm getting errors when persisting huge objects (byte[] may be > 5MB). Is it possible to store the data that way? I'm always getting an exception "java.lang.IllegalArgumentException: object too big: 4821537" when calling "insert" on DB...

Snippet:

private byte[] persistObject(String id, byte[] value){

    BasicDBObject doc = new BasicDBObject();
    doc.append("id", id);
    doc.append("value", value); // may be really huge! > 5MB of size

    try {
        getObjectCollection().save(doc);
    } catch (MongoException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return value;
}

Stacktrace:

java.lang.IllegalArgumentException: object too big: 4821537
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:217)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:180)
at com.mongodb.DBCollection.insert(DBCollection.java:72)
at com.mongodb.DBCollection.save(DBCollection.java:537)
at com.mongodb.DBCollection.save(DBCollection.java:517)

Thanks for your help/tips :)

Community
  • 1
  • 1
tim.kaufner
  • 1,247
  • 5
  • 13
  • 22

1 Answers1

2

I think your mongodb version is 1.6。BSON objects in MongoDB are limited in size(4MB)。Pls upgrade the mongodb version to 1.7+ . 16MB in v1.7/1.8, higher limits in the future。

nicholas
  • 64
  • 4
  • My Version is **db version v1.6.5** as this is the production release. I'm not sure if I should use an unstable development build in my project... Is there any other good no-sql db with a java interface that you would recommend? – tim.kaufner Mar 11 '11 at 08:07
  • I see mongodb's jira。1.8 rc2 is release。It haven't critical bugs。 You can try now。Other suggestions are membase and redis 。They are stable and have good performance。 – nicholas Mar 11 '11 at 08:14
  • I tried the version of mongodb you mentioned. It works! But you have to use the latest java-driver (version 2.5) to store large objects. Version 2.4 doesnt store them and throws exceptions too. Thanks for your help! – tim.kaufner Mar 11 '11 at 08:23
  • That's alright~。The latest java-driver has supported the new Mongo 1.8 features, like advanced post-processing on results (replace, merge, reduce, inline).Good News!~ – nicholas Mar 11 '11 at 08:38
  • What are the object (bson) limits for 1.8? Where to find them? Why do the object (bson) limits exist? – hkropp Jun 10 '11 at 07:14
  • Found an explanation here: http://stackoverflow.com/questions/4667597/understanding-mongodb-bson-document-size-limit – hkropp Jun 10 '11 at 07:34