-1

Is all of the javascript part in mongo shell commands executed on the server or on client or is it partial?

Let's say I have a command

db.mycollection.find({timestamp:{$lt:new Date()}}).forEach(function(doc){
    db.mycollection.remove(doc);
})
  1. Is the new Date() executed on the client or on server?
  2. Is the forEach part executed on the client or on the server?
Dushyant Bangal
  • 6,048
  • 8
  • 48
  • 80

1 Answers1

0

If you try to execute the above code into mongo shell and enable the mongodb profiler on the server on level 2, it records only following operations:

  • db.mycollection.find({timestamp:{$lt:new Date()}})
  • db.mycollection.remove(doc)

The mongo shell is an interactive JavaScript interface to MongoDB.

  • Is the new Date() executed on the client or on server? - On client
  • Is the forEach part executed on the client or on the server? - On client

You can notice the CPU utilization by mongo process on client if it processes large data.

You can also check this question on SO.

Atish
  • 4,277
  • 2
  • 24
  • 32