MongoClient eval引发分片集合异常

时间:2019-02-07 10:43:54

标签: mongodb mongo-java-driver

我更新了mongo-java-driver(2.11.3 => 3.9.0)和mongo(2.6 => 4.0.5),我的eval()函数function(source, target){db.getCollection(source).copyTo(target)}开始抛出异常:< / p>

[ERROR] ' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "Error: {\n\t\"ok\" : 0,\n\t\"errmsg\" : \"can't send a shardVersion with the 'eval' command, since you can't use sharded collections from 'eval'\",\n\t\"code\" : 20,\n\t\"codeName\" : \"IllegalOperation\"\n} :\n_getErrorWithCode@src/mongo/shell/utils.js:25:13\nDB.prototype.eval@src/mongo/shell/db.js:752:1\nDBCollection.prototype.copyTo@src/mongo/shell/collection.js:906:1\n@:1:27\n", "code" : 139, "codeName" : "JSInterpreterFailure" }
[ERROR]     at com.gwtplatform.dispatch.rpc.server.AbstractDispatchImpl.doExecute(AbstractDispatchImpl.java:164)
            ....
[ERROR]     at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
[ERROR]     at java.lang.Thread.run(Thread.java:748)
[ERROR] Caused by: com.mongodb.MongoCommandException: Command failed with error 139 (JSInterpreterFailure): 'Error: {
[ERROR]     "ok" : 0,
[ERROR]     "errmsg" : "can't send a shardVersion with the 'eval' command, since you can't use sharded collections from 'eval'",
[ERROR]     "code" : 20,
[ERROR]     "codeName" : "IllegalOperation"
[ERROR] } :

我知道我不能对分片集合使用eval。 Mongo文档:

  

不能将db.eval()与分片集合一起使用。一般来说,你   应该避免在分片集群中使用db.eval();然而,这是   可以对未分片的集合和数据库使用db.eval()   存储在分片群集中。 db.eval()

但是,我的集合没有被分片(它与以前的mongo和驱动程序版本一起使用)。

还是,我检查确定(如果我错了,请纠正我):

命令: db.getCollection("collection").getShardDistribution()

结果: Collection db.collection is not sharded.

有什么想法吗?

忘记添加使用驱动程序的Java代码:

import com.mongodb.DB;
DB db = ...;
db.eval(COPY_COLLECTION_FUNCTION, name, targetName);

0 个答案:

没有答案