![](/img/trans.png)
[英]MapReduce using MongoDB Java Driver failes with wrong type for BSONElement assertion
[英]MongoDB Java wrong Driver
我在使用 MongoDB 时遇到了问题。 我使用 sudo apt-get install mongodb 将它安装在我的 linux 服务器上。 当我现在尝试将我的 java 驱动程序连接到它时,它说
引起:com.mongodb.MongoIncompatibleDriverException:此版本的驱动程序与它所连接的一个或多个服务器不兼容:ClusterDescription{type=STANDALONE, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=127.0.0.1 :27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[2, 4, 10]}, minWireVersion=0, maxWireVersion=0, maxDocumentSize=16777216, roundTripTimeNanos=708358}]}
我在服务器上的 mongodb 版本似乎比我的驱动程序版本旧。 我的 java 驱动程序版本是 3.6 mongo-version 显示我是 2.4
我怎么能解决这个问题?
如果您使用 Docker 封装数据库,我建议将您的 ubuntu 版本更改为 16.04LTS,然后您的 mongod 将默认安装 2.6.10。
用java Driver运行就够了,不需要3.x。
这是 Dockerfile :
FROM ubuntu:16.04
RUN apt-get update && apt-get install -yq mongodb && apt-get clean && rm -rf /var/lib/apt/lists/*
ENTRYPOINT mongod --dbpath /data/db --rest
Ubuntu 的默认 mongodb 包是(截至 2018 年)版本 2.4。 这是一个相当旧的版本,与 3.x 客户端或 java 驱动程序不兼容。
从你的问题来看,我假设你没有承诺使用旧版本,所以你可能想要使用 3.x 版
这需要做更多的工作,而不仅仅是键入 apt install。 您可以按照 MongoDB 网站上的方法进行操作:
https://docs.mongodb.com/tutorials/install-mongodb-on-ubuntu/
尝试删除旧版本:
sudo apt-get purge --auto-remove mongodb-server
然后按照https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/安装最新的官方版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.