Is there a maximum MongoDB bit size?

The document I'm working on is extremely large. It collects user input from an extremely lengthy survey (like a monkey survey) and stores the responses in the mongodb database.

I am not surprising to get the following error

Error: Document exceeds maximal allowed bson size of 16777216 bytes 

If I cannot change the fields in my document, is there anything I can do? Is there a way to compress a document by removing a space or something like that?

Edit

Here is the structure of the document

 Schema({ id : { type: Number, required: true }, created: { type: Date, default: Date.now }, last_modified: { type: Date, default: Date.now }, data : { type: Schema.Types.Mixed, required: true } }); 

Example data field:

 { id: 65, question: { test: "some questions", answers: [2,5,6] } // there could be thousands of these question objects } 
+7
mongodb
source share
2 answers

One thing you can do is create your own mongoDB :-). Mongodb is open source and the document size limit is pretty arbitrary to provide a better layout design . You can simply change this line and create it for yourself. Be careful with that.

The most straightforward idea is to have each small question in another document with a field referencing its parent.

Another idea is to limit the number of documents in the parent . Suppose you are limited to N elements, then the parent looks like this:

 { _id : ObjectId(), id : { type: Number, required: true }, created: { type: Date, default: Date.now }, // you can store it only for the first element last_modified: { type: Date, default: Date.now }, // the same here data : [{ id: 65, question: { test: "some questions", answers: [2,5,6] } }, ... up to N of such things {} ] } 

Thus, by modifying the number N, you can make sure that you will be in 16 MB BSON. And to read the entire survey, you can choose

db.coll.find({id: the Id you need}) , and then combine the entire survey at the application level. Also don't forget makeIndex on id .

Try different things, do a test on your data and see what works for you.

+6
source share

You must use gridfs . It allows you to store documents in pieces. Here's the link: http://docs.mongodb.org/manual/reference/gridfs/

0
source share

All Articles