Get the App
SLTechnology News&Howtos  ›  Database  › 

MongoDB Notes XII-fixed set

Shulou Source: shulou.com Published: 2022-06-01 11:32:56 10月01日 Update

1. Characteristics of fixed sets

Fixed collections are indexed by default. Even _ id has no index.

Hesitation does not need to allocate space. His insertion speed is very fast.

The order of fixed collections is determined, resulting in very fast queries.

The most suitable application is log management.

2. Create a fixed collection

Creating a new fixed collection requires a size of 100 bytes and can store 10 documents

Db.createCollection ("mycoll", {size:100,capped:true,max:10})

Convert an ordinary set into a fixed set

Db.runCommand ({converToCapped: "persons", size:100000}) 3. Reverse sort. The default is insertion order.

Query fixed set mycoll and sort it in reverse

Db.mycoll.find (). Sort ({$natural:-1}) 4, tail cursor, but shell does not support drivers such as java and PHP.

Tail cursor concept

This is a special cursor that can only be used on a fixed level and body, and it will not destroy automatically when there is no result. He has been waiting for the result to arrive.

Tags: Cursor sort tail index result speed order support query normal special hesitation size bytes namely document log time concept feature Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno Huawei Xiaomi Shulou Tech Info