Imagine we have a Mongo instance used solely for cache. The collection simply is an array dump of the following
_id
key
value
expiration
However, someone on our project team. Stores it as
_id
0
1
2
Our backend (PHP), knows that 0 = "key", 1 = "value", 2 = "expiration". He said, "Its best to do it this way, so we aren't storing a long key name in every record in Mongo"
This made sense originally to me, since each document is stored on its own. However, using any management tool or trying to manipulate our data outside of our application is near impossible. Its like looking at 1's and 0's. So I went out to test this.
I made a small Mongo collection of named keys and numerics. After doing this. I ran a db.foo.stats()
on both of them.
They matched every stat. So I guess my question is. If we have a key named VeryLongKeyDescriptiveText
, and its stored in 1000 records. Is that the same physical size as storing 0
and the respective value? (My test says yes, but I don't understand how Mongo does this).
My testing is two collections (control & test). Using the two above key-value setups. Each collection currently has 3 documents that consist of a name, some base64 loren ipsum text, and unix timestamp for expiration. Both collections have the same exact data, with the exception of the keys which in the test are (0,1,2) instead of (key, value, expiration). Here are the outputs of stats()
for both of them: http://pastebin.com/tTt7VzwQ