[JAVA-1782] Document that eval is deprecated in 3.0 Created: 28/Apr/15  Updated: 24/Aug/15  Resolved: 28/Apr/15

Status: Closed
Project: Java Driver
Component/s: Documentation
Affects Version/s: 3.0.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: William Chan Assignee: Unassigned
Resolution: Done Votes: 0
Labels: documentation
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DRIVERS-225 Deprecate eval helpers Closed

 Description   

Based on http://docs.mongodb.org/manual/reference/command/eval/ and http://docs.mongodb.org/manual/reference/method/db.eval/, eval is deprecated in 3.0.

DB#eval and DB#doEval should be marked as deprecated. Also, I would really appreciate comments suggesting what to use instead of eval.

To quote the existing comments: eval "Evaluates JavaScript functions on the database server. This is useful if you need to touch a lot of data lightly, in which case network transfer could be a bottleneck."

What is a good alternative to this?



 Comments   
Comment by Ross Lawley [ 28/Apr/15 ]

Added a DRIVERS-225 for other drivers to ensure they deprecate any $eval command helpers.

Comment by Ross Lawley [ 28/Apr/15 ]

Hi willchan83,

In 3.0.0 MongoClient.getDB() was deprecated meaning that all code under DB has been deprecated - including DB#eval and DB#doEval. We haven't added a eval helper in MongoDatabase (the DB replacement) but there is the runCommand helper for running arbitrary commands.

The eval command was deprecated in SERVER-17453 and was documented in DOCS-4899. The reasons for the decision are mentioned in the SERVER ticket:

There are a number of issues with the eval command.

  1. Compatibility: eval was developed before the introduction of sharding. The eval command does not work on sharded clusters at all.
  2. Performance: Takes a global lock by default. If eval is with the noLock option, it implies that the javascript could just as easily be run from a client program.
  3. Security: You must have access to all actions on all resources in order to run eval. Security best practices depend on being able to segment privileges to actions, and eval gives too broad a range of powers.
  4. Maintenance: The server must move to a model where javascript is executed "out of process" for a number of reasons; maintaining support for eval makes this very difficult.

There is no alternative from a driver perspective other than coding the functionality from the driver. However, you still can use the shell directly, which is a javascript runtime.

I hope that answers your question and as there is no work to be done I'm going to close this ticket "Works as Designed".

For future reference, the best place for general questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailinglist or stackoverflow as you will reach a boarder audience there.

Generated at Thu Feb 08 08:55:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.