MongoDB Tip: Create Short Field Names

WBOY
풀어 주다: 2016-06-07 16:29:22
원래의
1072명이 탐색했습니다.

MongoDB’s dynamic schema and document-based data structure offer a lot of flexibility in development, but it’s important to understand how your document construction can affect available memory in your application. It’s incredibly valua

MongoDB’s dynamic schema and document-based data structure offer a lot of flexibility in development, but it’s important to understand how your document construction can affect available memory in your application. It’s incredibly valuable to optimize storage size of your documents, and one easy way to do this is by shortening your field names.

MongoDB stores all field names in each BSON document. In most cases the space is inconsequential, but when your data set grows to include millions of documents (and potentially collections), the extra bytes in long field names can add up. If document or schema overhead is a significant concern, consider shortening your field names.

For example, instead of the field names in the following document:

{ first_name: ?“Joseph”, address: “345 Caroll Street” , telephone: “19176253475”}
로그인 후 복사


Consider shortening the names to:

{ fname: ?“Joseph”, addr: “345 Caroll Street” , tel: “19176253475”}
로그인 후 복사


The Use Case

One case where this might be useful is when you are logging real-time data points such as web stats. Here, you have many small documents being added every minute, second and hour of the day. You might have a document that looks like this:

{"_id" : "512d35b0400fed3b997cd9c9" ,
로그인 후 복사
로그인 후 복사
"hour" : "Thu Mar 05 2013 10:00:00 GMT-0500 (EST)" ,
로그인 후 복사
"site" : "abc" , "u" : 1 ,
로그인 후 복사
"pageviews" : 1}
로그인 후 복사


Having longer field names could end up taking up a lot of disk space over time, while using shorter field names with have a larger impact on your disk savings. Consider cutting down your field names like so:

{"_id" : "512d35b0400fed3b997cd9c9" ,
로그인 후 복사
로그인 후 복사
"h" : "Thu Mar 05 2013 10:00:00 GMT-0500 (EST)" ,
로그인 후 복사
"s" : "abc" , "u" : 1 ,
로그인 후 복사
"pv" : 1}
로그인 후 복사


Depending on your document size, using shorter field names will have a tangible benefit to your application.

  • Learn more about MongoDB for Analytics

Update: Here is a link to the two server tickets that are being worked on to optimize document storage at the database level.?

  • SERVER-863
  • SERVER-164
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿