MongoDB fixed collections

create

db.createCollection(
'fix',
{      
    capped:true,
    size:1000,
    max:5
}
)

size  is the size of the entire collection space, the unit is [KB]

max  is the number of collection documents online, the unit is [pieces]

 

insert raw data

db.txt.insertMany(
[
    {a:3},
    {a:1},
    {a:2},
    {a:4},
    {a:5},
]   
)

 

A fixed set is similar to a fixed-length queue. If the size exceeds the specified size after adding an element, the head element will be deleted.

db.fix.insert({a:11})

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325119461&siteId=291194637