How to create a limited collection using mongoose?

I am trying to create a limited collection using Mongoose, however the following creates a collection that is not limited:

var schema = new mongoose.Schema( { Name: { type: String }, Text: { type: String } }, { capped: { max: 5, size: 1000000 } }); 

I am sure that I am following the documentation example correctly, but obviously I am doing something wrong.

+6
source share
2 answers
 new Schema({..}, { capped: { size: 1024, max: 1000, autoIndexId: true } }); 
+6
source
 new Schema({..}, { capped: { size: 1024, max: 1000, autoIndexId: true } }); 
  • size is the maximum bytes in memory to which your database is not limited or to which your old records are not deleted.
  • max determines the number of maximum records that will be stored in the database until closed.

    You must define the size component regardless of the maximum component. Because if your size is used before reaching the maximum, then too corking will begin, but on the contrary is not true.

+2
source

Source: https://habr.com/ru/post/927994/


All Articles