Docs Home → MongoDB Manual
The native method listed here is for the legacy mongo shell.
mongo
To use native methods in mongosh, see Native Methods in mongosh.
mongosh
_rand()
0
1
This function provides functionality similar to the Math.rand() function from the standard library.
Math.rand()