Many people think that there is a problem with the database taking up too much memory. In fact, this is not a problem at all and does not need to be solved.
First of all, the primary task of a database is to manage data. How to provide data queries faster is a problem that all databases need to solve. The solutions of each company are almost the same. Whether it is SQLServer, MySQL, or MongoDB, they all trade space for efficiency. In layman's terms, it is to use as much memory as possible and load all useful things (indexes, data, etc.) into memory as much as possible to improve running speed. So, this is definitely not a bug, but expected behavior. Thinking about it conversely, if a database runs slowly in order to save memory, this violates the basic purpose of a database.
Once you understand this, let’s look at your question.
If you are in a production environment, there is no need to reclaim memory at all, because it will only make the instant efficiency very poor. And it doesn't work, because the database will reload the data from the disk later, causing high disk IO and affecting the write speed. So in the end, you only get temporary free memory, and query speed and write speed will be greatly affected. You can figure it out for yourself whether it’s a good deal or not.
If this is a development environment and you don’t need to worry about these problems, restarting mongod can easily solve the problem. In addition, because you may want to further clear the data in the cache, you can use the Linux command: echo 3 > /proc/sys/vm/drop_caches
Reference: Does MongoDB require a lot of RAM? How do you empty the buffers and cache on a Linux system?
I am also learning mongodb recently. I recommend you mongodb learning materials http://www.hubwiz.com/course/54bdfcb188dba012b4b95c9c/
Many people think that there is a problem with the database taking up too much memory. In fact, this is not a problem at all and does not need to be solved.
First of all, the primary task of a database is to manage data. How to provide data queries faster is a problem that all databases need to solve. The solutions of each company are almost the same. Whether it is SQLServer, MySQL, or MongoDB, they all trade space for efficiency. In layman's terms, it is to use as much memory as possible and load all useful things (indexes, data, etc.) into memory as much as possible to improve running speed. So, this is definitely not a bug, but expected behavior. Thinking about it conversely, if a database runs slowly in order to save memory, this violates the basic purpose of a database.
Once you understand this, let’s look at your question.
Reference:
Does MongoDB require a lot of RAM?
How do you empty the buffers and cache on a Linux system?