JavaScript code in the server-side to avoid network latency and data-transfer of large quantities overhead

23 views
Skip to first unread message

Joachim Hagege

unread,
Apr 21, 2016, 7:49:45 AM4/21/16
to mongodb-user

I need to process 100s of Gigas of DB on the Server Side and the way I'm doing it right now is by loading a JS file with the shell.

i.e: mongo ipaddress:27017/database_name script.js

This works fine but problem is I can see that the data is being processed on the MongoDB shell in the CLIENT side, and all the data is passed through the network (which is a big overhead we would rather avoid).

Is there any way to process the data ONLY on the server side, without transferring all the data ?

Thanks a lot.

Kevin Adistambha

unread,
Apr 29, 2016, 1:42:32 AM4/29/16
to mongodb-user

Hi Joachim,

I need to process 100s of Gigas of DB on the Server Side and the way I’m doing it right now is by loading a JS file with the shell.

i.e: mongo ipaddress:27017/database_name script.js

Is there any way to process the data ONLY on the server side, without transferring all the data ?

You can open the mongo shell directly on the server so that the script.js file will be executed on the server, as described in Running .js files via a mongo shell Instance on the Server.

For example, you can:

  1. upload your script.js to the server
  2. ssh directly into it
  3. execute mongo localhost:27017/database_name script.js

Since the mongo shell is opened on the server, the script will run on it.

The tradeoff is that while the script is running, it will create a resource contention in the server with the mongod process. Please ensure that this tradeoff is acceptable before deploying this method into production.

Best regards.
Kevin

Reply all
Reply to author
Forward
0 new messages