MongoDB empty string value vs null value

前端 未结 3 1241
隐瞒了意图╮
隐瞒了意图╮ 2021-02-04 01:17

In MongoDB production, if a value of a key is empty or not provided (optional), should I use empty string value or should I use null for value.

1) Is there any pros vs c

3条回答
  •  梦毁少年i
    2021-02-04 01:49

    This question has been answered at least 4 times by me and a Google search will get you a lot of information.

    You must take into consideration what removing the key means. If your document will eventually use that schema in most of its defined state, within the application, then you could be seeing a lot of movement of the document, this neuts the benefit of no having these keys: space. Those couple of bytes you will save in space will be rendered useless and you will get a swiss cheese effect.

    However if you do not use these fields at all then having those few extra bytes with millions of documents in your working set could cause real problems that need not be there (if you for some reason want to shove that many documents into your working set), as for the space issue, MongoDB fundamentally has a space issue and I have not really known omitting a couple of keys to do anything to help that.

提交回复
热议问题