HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
MongoDB fixed set (Capped Collections) performance is excellent and has a fixed size collection for a fixed size, we can imagine it as a circular queue, when the collection space is exhausted, and then insert the element will cover most of the initial head Elements!
Let's create a fixed set by createCollection and capped option is set to true:
>db.createCollection("cappedLogCollection",{capped:true,size:10000})
You can also specify the number of documents, plus max: 1000 Property:
>db.createCollection("cappedLogCollection",{capped:true,size:10000,max:1000})
Determine whether the collection of fixed collection:
>db.cappedLogCollection.isCapped()
If you need to convert an existing collection of fixed collection you can use the following command:
>db.runCommand({"convertToCapped":"posts",size:10000})
The code above our existing collection of posts converted to a fixed set.
Fixed set of documents stored in accordance with the insertion order, by default the query is inserted in accordance with the order to return, it can also be used to adjust the return $ natural order.
>db.cappedLogCollection.find().sort({$natural:-1})
You can insert and update, but the update can not exceed the size of the collection, or the update fails, can not be deleted, but you can call drop () to delete all the rows in the collection, but after a drop to explicitly rebuild the collection.
Max on a 32-bit machine cappped collection of about 482.5M, 64-position is limited only by the size of the file system.