0

I work this the .NET driver for MongoDB. My question is quite :

What is preferable and why :

process data using javascript on the MongoDB server

or

load thd data to client and do all the work using the driver methods ?

gilp
  • 571
  • 2
  • 6
  • 19

2 Answers2

5

You should avoid processing data on the mongodb server using JavaScript if at all possible. The reason is that the JavaScript engine is single-threaded. This means that only one thread can be running the JavaScript engine at one time. As you can imagine, this will greatly impact performance if you have multiple clients connecting to mongodb -- all of these request will be serialized.

William Z
  • 10,989
  • 4
  • 31
  • 25
4

You should not fall into the same trap of trying to use "stored procedures" as many who use JS functions think they are. I explain fairly well why you shouldn't use JS in queries here: is procedure exist in mongodb.

Really for data processing in MongoDB you have three options:

  • Map reduce
  • Client side
  • Pre-aggregation.

All of those methods are more preferrable and way better. As to which one is more preferrable in your situation: it all depends on what you are trying to accomplish.

Of course as of 2.2 (just released) you got the aggregation framework which by-passes the JS engine and gives you more flexibility.

Community
  • 1
  • 1
Sammaye
  • 43,242
  • 7
  • 104
  • 146