( From: http://api.mongodb.org/wiki/current/Using a Large Number of Collections.html )
MongoDB : Using a Large Number of Collections
This page last changed on Dec 01, 2010 by eliot.
A technique one can use with MongoDB in certain situations is to have several collections to store information instead of a single collection. By doing this, certain repeating data no longer needs to be stored in every object, and an index on that key may be eliminated. More importantly for performance (depending on the problem), the data is then clustered by the grouping specified.
For example, suppose we are logging objects/documents to the database, and want to have M logs: perhaps a dev log, a debug log, an ops log, etc. We could store them all in one collection 'logs' containing objects like:
{ log : 'dev', ts : ..., info : ... }
However, if the number of logs is not too high, it might be better to have a collection per log. We could have a 'logs.dev' collection, a 'logs.debug' collection, 'logs.ops', etc.:
// logs.dev: { ts : ..., info : ... }
Of course, this only makes sense if we do not need to query for items from multiple logs at the same time.
Generally, having a large number of collections has no significant performance penalty, and results in very good performance.
Limits
By default MongoDB has a limit of approximately 24,000 namespaces per database. Each collection counts as a namespace, as does each index. Thus if every collection had one index, we can create up to 12,000 collections. Use the --nssize parameter to set a higher limit.
Be aware that there is a certain minimum overhead per collection -- a few KB. Further, any index will require at least 8KB of data space as the b-tree page size is 8KB. Certain operations can get slow if there are a lot of collections and the meta data gets paged out.
--nssize
If more collections are required, run mongod with the --nssize parameter specified. This will make the <database>.ns file larger and support more collections. Note that --nssize sets the size used for newly created .ns files -- if you have an existing database and wish to resize, after running the db with --nssize, run the db.repairDatabase() command from the shell to adjust the size.
Maximum .ns file size is 2GB.
How does the amount of namespace exactly compare to the nssize (file size)? Is there a way to calculate this size or does the size depend on the stored data? What is exactly stored in a *.ns file?
分享到:
相关推荐
MongoDB: The Definitive Guide MongoDB is a powerful, flexible, and scalable generalpurpose database. It combines the ability to scale out with features such as secondary indexes, range queries, ...
- 启动MongoDB:`sudo systemctl start mongodb` - 设置开机启动:`sudo systemctl enable mongodb` 6. **手动创建启动脚本** 如果系统确实不支持Init.d,但需要使用旧的启动方式,可以手动创建一个启动脚本。这...
深入学习MongoDB:Scaling MongoDB && 50 Tips and Tricks for MongoDB Developers深入学习MongoDB中文版Scaling MongoDB英文版50 Tips and Tricks for MongoDB Developers英文版高清完整目录3本打包合集
1. 连接MongoDB:输入`mongo.exe`命令,连接到本地MongoDB服务。 2. 创建数据库:使用`use <database_name>`命令,如`use testdb`,创建一个名为"testdb"的数据库。 3. 插入数据:在选定的数据库中,使用`db....
文档层使用MongoDB:registered:有线协议,允许通过现有的MongoDB:registered:客户端绑定使用MongoDB:registered:API。 所有持久数据都存储在FoundationDB键值存储中。 文档层实现了MongoDB:registered:API(v ...
最近Mongodb会经常突然挂掉,检查日志发现如下的错误: 代码如下: tcmalloc: large alloc 2061584302080 bytes == (nil) @ Tue Nov 26 17:45:04.539 out of memory, printing stack and exiting: 0xdddd81 0x6cfb4e...
什么是 MongoDB MongoDB 简介 MongoDB 特点 安装与配置 安装 MongoDB 启动与配置 MongoDB 基本操作 数据库和集合 文档操作 查询操作 基本查询 高级查询 索引与性能优化 创建索引 索引类型 索引优化 聚合操作 聚合...
mongodb 命令行mongod启动报错 about to fork child process, waiting until server is ready for connections. forked process: 3560 ERROR: child process failed, exited with error number 1 To see additional ...
描述 PM2模块可自动监视mongodb的生命体征: 查询,输入,更新,删除 连接数 已用存储空间 网络速度(输入和输出) 代表名称和状态 pm2-mongodb ... pm2 set pm2-mongodb:ip 42.42.42.42 (我的mongod
docker run -d --name mongodb -p 27017:27017 -v /data/mongodb:/var/lib/mongodb anapsix/mongodb 作为客户: docker run -it --rm anapsix/mongodb mongo --help 配置 您可以像通常那样通过命令行传递配置选项...
Spring集成MongoDB官方指定jar包:spring-data-mongodb-1.4.1.RELEASE.jar
mongodb人偶模块 目录 概述 从OS存储库或从MongoDB社区/企业存储库在RHEL / Ubuntu / Debian上安装MongoDB。 模块说明 ...如果只想使用默认选项安装服务器,则可以运行include mongodb::server 。
sql到mongodb 将SQL表转换为MongoDB集合的Java工具 轻松将 MSSQL 表转换为 MongoDB。 从下载 SQL Server JDBC 驱动程序 将 SQLJDBC... MSSql_Table_To_MongoDB_Collection mssql_table_name number_of_rows_at_a_time
羽毛mongodb 用于数据库适配器,使用用于。 $ npm install --save mongodb feathers-mongodb ... connect ( 'mongodb://localhost:27017/feathers' ) . then ( client => { app . use ( '/messages' ,
2. **灵活的数据模型**: MongoDB的数据模型基于集合(collections)和文档(documents)。集合类似于关系数据库中的表,文档则是集合中的数据记录,由键值对组成。 3. **分布式架构**: MongoDB支持横向扩展,可以跨...
The IT industry is undergoing a revolution with the introduction of Big Data. Big Data is posing challenges to the traditional RDBMS way of storing and processing data hence paving ways to newer ...