Table of Contents
一、创建Capped Collection 
二、Capped Collection的用途
三、注意事项
Home Database Mysql Tutorial 【MongoDB】Mongodb数据库之Capped Collection集合

【MongoDB】Mongodb数据库之Capped Collection集合

Jun 07, 2016 pm 02:59 PM
mongodb database

Capped Collection是性能出色的有着固定大小的集合,以LRU(least Recently Used,最近最少使用)规则和插入顺序执行age-out(老化移出)处理,自动维护集合中对象的插入顺序。 一、创建Capped Collection 创建时候要预先指定大小,如果空间用完,新添加的对

Capped Collection是性能出色的有着固定大小的集合,以LRU(least Recently Used,最近最少使用)规则和插入顺序执行age-out(老化移出)处理,自动维护集合中对象的插入顺序。

一、创建Capped Collection 

创建时候要预先指定大小,如果空间用完,新添加的对象将会取代集合中最近的对象。更新如果超出了collectiond 大小,则会更新失败。虽然不允许删除,但是可以调用drop方法删除集合中所有的文档。 删除后要显示重建集合。在32机器上,一个capped collection的最大值约是482.5M,64位只受系统文件大小的限制。

【MongoDB】Mongodb数据库之Capped Collection集合

一个普通的collection转换为Capped Collection,只要调用convertToCapped()命令即可;

【MongoDB】Mongodb数据库之Capped Collection集合

二、Capped Collection的用途

Capped Collection是mongodb中日志机制的首选,mongodb没有使用日志文件,而是吧日志文件存储在数据库中。在一个没有索引的capped collection中插入对象的速度与在文件系统中记录的日志速度相当。

在内存中缓存一些对象,比如,计算出来的统计信息一般需要在collection上建立一个索引,因为使用缓存往往是读比写多。 

可以利用capped collection的age-out特性,省去写crontab脚本执行人工归档的工作。

三、注意事项

1.如果写比读多,最好不要在上面创建索引;

2,使用natual ordering可以有效地检索最近插入的元素,因为capped collection能够保证自然排序就是插入的顺序。

3. capped collection不能被shard.

4. 可以在创建capped collection时指定collection中能够存放的最大文档数。 





Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The difference between nodejs and vuejs The difference between nodejs and vuejs Apr 21, 2024 am 04:17 AM

Node.js is a server-side JavaScript runtime, while Vue.js is a client-side JavaScript framework for creating interactive user interfaces. Node.js is used for server-side development, such as back-end service API development and data processing, while Vue.js is used for client-side development, such as single-page applications and responsive user interfaces.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Nodejs front-end and back-end distinction Nodejs front-end and back-end distinction Apr 21, 2024 am 03:43 AM

Node.js can be used for both front-end (handling user interface and interactions) and back-end (managing logic and data). The front-end uses HTML, CSS, and JavaScript frameworks, while the front-end uses Node.js framework, database, and cloud services. The focus is different (the front-end focuses on experience, the back-end focuses on functionality), the running environment is different (the front-end is in the browser, the back-end is on the server), and the tools are different (the front-end and back-end use different code compilation and packaging tool sets), although both use JavaScript , but with access to different APIs and libraries.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Is it difficult to learn nodejs on the front end? Is it difficult to learn nodejs on the front end? Apr 21, 2024 am 04:57 AM

For front-end developers, the difficulty of learning Node.js depends on their JavaScript foundation, server-side programming experience, command line familiarity, and learning style. The learning curve includes entry-level and advanced-level modules focusing on fundamental concepts, server-side architecture, database integration, and asynchronous programming. Overall, learning Node.js is not difficult for developers who have a solid foundation in JavaScript and are willing to invest the time and effort, but for those who lack relevant experience, there may be certain challenges to overcome.

What to do if navicat expires What to do if navicat expires Apr 23, 2024 pm 12:12 PM

Solutions to resolve Navicat expiration issues include: renew the license; uninstall and reinstall; disable automatic updates; use Navicat Premium Essentials free version; contact Navicat customer support.

Use Golang functions to build message-driven architectures in distributed systems Use Golang functions to build message-driven architectures in distributed systems Apr 19, 2024 pm 01:33 PM

Building a message-driven architecture using Golang functions includes the following steps: creating an event source and generating events. Select a message queue for storing and forwarding events. Deploy a Go function as a subscriber to subscribe to and process events from the message queue.

See all articles