[mongodb] Is there any option to limit mongodb memory usage?

There is no reason to limit MongoDB cache as by default the mongod process will take 1/2 of the memory on the machine and no more. The default storage engine is WiredTiger. "With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache."

You are probably looking at top and assuming that Mongo is using all the memory on your machine. That is virtual memory. Use free -m:

              total        used        free      shared  buff/cache   available
Mem:           7982        1487        5601           8         893        6204
Swap:             0           0           0

Only when the available metric goes to zero is your computer swapping memory out to disk. In that case your database is too large for your machine. Add another mongodb instance to your cluster.

Use these two commands in the mongod console to get information about how much virtual and physical memory Mongodb is using:

var mem = db.serverStatus().tcmalloc;

mem.tcmalloc.formattedString

------------------------------------------------
MALLOC:      360509952 (  343.8 MiB) Bytes in use by application
MALLOC: +    477704192 (  455.6 MiB) Bytes in page heap freelist
MALLOC: +     33152680 (   31.6 MiB) Bytes in central cache freelist
MALLOC: +      2684032 (    2.6 MiB) Bytes in transfer cache freelist
MALLOC: +      3508952 (    3.3 MiB) Bytes in thread cache freelists
MALLOC: +      6349056 (    6.1 MiB) Bytes in malloc metadata
MALLOC:   ------------
MALLOC: =    883908864 (  843.0 MiB) Actual memory used (physical + swap)
MALLOC: +     33611776 (   32.1 MiB) Bytes released to OS (aka unmapped)
MALLOC:   ------------
MALLOC: =    917520640 (  875.0 MiB) Virtual address space used
MALLOC:
MALLOC:          26695              Spans in use
MALLOC:             22              Thread heaps in use
MALLOC:           4096              Tcmalloc page size