热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MongoDBTip:CreateShortFieldNames

MongoDB’sdynamicschemaanddocument-baseddatastructureofferalotofflexibilityindevelopment,butit’simportanttounderstandhowyourdocumentconstructioncanaffectavailablememoryinyourapplication.It’sincrediblyvalua

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
推荐阅读
  • 本文介绍了在Windows系统下安装Mongodb的详细步骤和注意事项。包括下载Mongodb官方文档、选择64位安装包、配置环境变量、命令行启动Mongodb等。通过本文的指导,用户可以轻松完成Mongodb的安装并进行相关操作。 ... [详细]
  • 我有一个非常大的TSV文件。第一行是标题。如果字段为空白,则以下各行包含数 ... [详细]
  • redis知识汇总[随笔记录]
      ... [详细]
  • --文件IO:分简单模式与完全模式。简单模式在做一些简单的文件操作时较为合适。但是在进行一些高级的文件操作的时候,简单模式就显得力不从心。例如同时读取多 ... [详细]
  • 样式迁移(风格迁移)
    原文来源:https:arxiv.org、https:github.com作者:FujunLuan、SylvainParis、EliShechtman、KavitaB ... [详细]
  • 错误:requireluasql.mysqlstdin:1:moduleluasql.mysqlnotfound:nofieldpackage.preload[lua ... [详细]
  • 基于Redis实现分布式锁剖析
    之前的文章《分布式锁详解-分别利用Zookeeper和数据库实现分布式锁》,由于篇幅太长,又碰上加班时间不够充裕,所以没有把Redis的实 ... [详细]
  • luarestyqlesswebUI界面运行
    lua-resty-qless-web是lua-resty-qless的web管理界面以及lua-resty-template模版引擎开发的,里面实现了一个简单的路由功能备注:de ... [详细]
  • 1、概念解读1.1什么是链接?链接是一种在共享文件和访问它的用户的若干目录项之间建立联系的方法。Linux系统中有两种链接:硬链接(HardLink)和软链接(SoftLink), ... [详细]
  • 《计算机专业英语基础知识》由会员分享,可在线阅读,更多相关《计算机专业英语基础知识(25页珍藏版)》请在人人文库网上搜索。1、专业英语知识补充,本章学习 ... [详细]
  • php还能用多少年(php还行吗)
    导读:很多朋友问到关于php还能用多少年的相关问题,本文编程笔记就来为大家做个详细解答,供大家参考,希望对大家有所帮助!一起来看看吧!本文目录一览: ... [详细]
  • nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • PHP调试凶器Xdebug安装配置教程:PHP调试利器Xdebug安装配置教程作者:zhanhailiang日期:2013-03-111.简述引用官方描述:TheXdebugext ... [详细]
  • 爬虫框架Scrapy(三)
    正文共:2957字6图预计阅读时间:8分钟每日分享Bethetypeofpersonyouwanttomeet.努力变成理想的模样。小闫笔记࿱ ... [详细]
  • springcloud:微服务涉及哪些技术、有哪些核心组件(二)
    0.引言上一期我们介绍了什么是微服务,微服务的基础概念,那么本期我们来介绍一下微服务涉及的技术点以及所需要的组件1.微服务涉及哪些技术1.1、基础 ... [详细]
author-avatar
果粒仙子妹妹
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有