[SERVER-10213] Allow eval() against a SINGLE document in a sharded collection (A.K.A findAndEval) Created: 15/Jul/13  Updated: 17/Mar/16  Resolved: 15/Jul/13

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: 2.4.5
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: ahildoer Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux


Issue Links:
Duplicate
duplicates SERVER-458 JavaScript $function in update Closed
Participants:

 Description   

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.



 Comments   
Comment by Eric Reynolds [ 17/Mar/16 ]

This is not necessarily a dup of SERVER-458, if the function is interpreted as the projection.

My use case is that have some large documents, and I would like my queries to only return a subset of the information. For example if I wanted only the keys I'd like to be able to do this

db.collection.find(
    {...},
    function(d) {
        return Object.keys(d);
    }
)

This is particularly important when the query is being made from another process to avoid sending back lots of unnecessary data.

Comment by Scott Hernandez (Inactive) [ 15/Jul/13 ]

dup of SERVER-458

Generated at Thu Feb 08 03:22:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.