ホームページ > データベース > mysql チュートリアル > MongoDB Tip: Create Short Field Names

MongoDB Tip: Create Short Field Names

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
リリース: 2016-06-07 16:29:22
オリジナル
1139 人が閲覧しました

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
関連ラベル:
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
Mac での mongodb の構成エラー
から 1970-01-01 08:00:00
0
0
0
symfony2 mongodb の使用
から 1970-01-01 08:00:00
0
0
0
mongodbのパラメータの理解
から 1970-01-01 08:00:00
0
0
0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート