Question

All the documents in my mongoDB collection will have an array of integers. I don't need more than 32 bits for each integer, and the length of the integer array will be identical for each document.

The clients of my application will frequently be updating individual fields within the arrays.

If I have 5000 to 10000 documents with arrays of 256 integers, will mongo db waste space because it needs to be prepared for me to change the contents of my arrays to non-integer datatypes, OR change the length of the array?

Will the design of mongoDB make updating individual integers within my arrays very inefficient when compared to a traditional relational database?

Presume I'm using the update array syntax describe here: http://docs.mongodb.org/manual/applications/update/#update-arrays

Was it helpful?

Solution

will mongo db waste space because it needs to be prepared for me to change the contents of my arrays to non-integer datatypes OR change the length of the array?

No it will not waste space. Rather than thinking about this in terms of the ability to change data types or changing the array length, I would concentrate on MongoDB's padding factor whereby it adaptively learns whether documents tend to grow. Since your document sizes will be very similar, your padding factor will tend towards 1 (i.e. almost no additional padding added on the document size).

Will the design of mongoDB make updating individual integers within my arrays very inefficient when compared to a traditional relational database?

Since embedded arrays don't have an exact relational equivalent, the comparison is not obvious. You might assume the relational equivalent to be a JOIN. In this case, I believe MongoDB will work out to be faster, since a JOIN has a cost of its own.


As an additional note, 5,000 to 10,000 documents is miniscule given the volume of data MongoDB can handle. As long as you are specifying an indexed criteria on the update (such as _id) you really don't have any space or performance considerations to worry about here. However since your documents are not tiny, the one thing I would watch for is trying to load the entire document at once in a find query, you might prefer to project find queries for specific fields only; and when querying the array you might want to consider $slice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top