Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10213

Allow eval() against a SINGLE document in a sharded collection (A.K.A findAndEval)

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.5
    • Component/s: JavaScript
    • Labels:
      None
    • Environment:
      Linux

      I know there are some fundamental limitations of running eval() on a sharded cluster for general purpose JavaScript, but I believe that my specific use case is feasible given the limitations of sharding. The difference for my use case is that I want eval() against only a single document for read or write. You could think of it as a modification of findAndModify() where we want to find and eval, instead of modify. This means that the eval() command can be run on the shard itself (monogd server), and not in the router (mongos server).

      I believe that this is possible with the following semantics:

      1. Client app issues request to a mongos server. The request contains a document _id (or some other reference containing the entire shard key) and the javascript to eval() against the document.
      2. command is routed to the correct shard (rather than executing the command on the mongos)
      3. the shard containing the document write locks for the collection
      4. the shard pulls the document and executes the JavaScript against the document
      5. access to any other document for read/write/whatever is prohibited.
      6. once JavScript finished modifying the document, the document is stored.
      7. write lock released for collection on that shard.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ahildoer ahildoer
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: