mongodb - Track mb used per each user
问题描述
I'm trying to figure out a way to implement a tracking system based on how many megabytes a user has used for a MongoDB database.
Say I have a email field value for each document associated with a user (myemail@example.com
).
A user can append new documents to multiple collections in the database whenever he / she wants through a web-application, but is not allowed to exceed 100MB in total storage.
Basically I want to track when all associated documents for each email has exceeded 100MB, respectively.
How can I with high performance and accuracy track this?
Thanks!
解决方案
您可以使用$bsonSize来计算一组文档占用了多少空间。
MongoDB 曾经有一个带有 MMAP 的配额系统,但这不是 Wired Tiger 提供的功能。
推荐阅读
- javascript - 图像地图为圆形区域设置背景图像
- .net - 如何使用 OrchardCore CMS 通过 GraphQL 从 MediaFields 获取所有内容?
- python - 通过传递坐标在棋盘上划出白色方块
- asp.net-core - 动态创建和销毁 Blazzor 客户端组件?
- ios - NSRangeException 由 String.subscript.getter
- python - 如何在python中的for循环函数的最后删除空格/跳转到下一行
- c# - 使用 Web API 在不写入磁盘的情况下读取 HTTP 文件和表单数据
- macos-catalina - 由于 OS Catalina,FICO Xpress Workbench 无法工作,产生错误“spawn mosel ENOENT”
- css - CSS变换过渡问题
- laravel - 404异常的Laravel自定义页面