How do you create a capped collection using mongoose?

后端 未结 3 1376
难免孤独
难免孤独 2021-01-12 03:39

I\'m trying to create a capped collection using Mongoose, however the following creates a collection that is not capped:



        
3条回答
  •  -上瘾入骨i
    2021-01-12 04:14

    new Schema({..}, { capped: { size: 1024, max: 1000, autoIndexId: true } });
    
    • size is the maximum bytes in memory till which your database is not capped or till which your older records are not removed.
    • max defines the number of maximum records which database will hold before capping.

      You must define size component irrespective of max component. Because if your size is used before reaching max then too capping will start but vice versa is not true.

提交回复
热议问题