MongoDB 3.6 shell "Buffer is not defined"


I write a js script for mongodb 3.6.3 (Ubuntu 18.04) where I want to use js / nodejs “Buffer”, but script execution says:

 E QUERY    [thread1] ReferenceError: Buffer is not defined : 

The minimal script where I can reproduce the issue is:

let buff = new Buffer(10);
buff[1] = 1;

And the command line:

mongo localhost:27017/dev minimal.js

Can anybody help me, what did I wrong, or what am I miss?

Thank you

Not all of js stuff is available in legacy mongo shell.

Try with with the new mongosh. If it is still not working you might want to use the nodejs driver directly.

This works well with the new MongoDB Shell (mongosh).