开发者

Exception when storing large BasicDBObject to mongodb with java

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();
    }开发者_JAVA技巧 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 :)


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。

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜