如何配置支持会话的MongoDB集群? [英] How to configure a MongoDB cluster which supports sessions?

查看:310
本文介绍了如何配置支持会话的MongoDB集群?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想探索MongoDB的新事务功能并使用Spring Data MongoDB.但是,我收到异常消息该客户端连接到的MongoDB集群不支持会话".关于MongoDB 3.7.9的配置的任何提示都值得赞赏.

I want to explore the new transaction feature of MongoDB and use Spring Data MongoDB. However, I get the exception message "Sessions are not supported by the MongoDB cluster to which this client is connected". Any hint regarding the config of MongoDB 3.7.9 is appreciated.

stacktrace的开头是:

The stacktrace starts with:

com.mongodb.MongoClientException : 该客户端连接到的MongoDB集群 在com.mongodb.MongoClient.startSession(MongoClient.java:555)〜[mongodb-driver-3.8.0-beta2.jar:na] 在org.springframework.data.mongodb.core.SimpleMongoDbFactory.getSession(SimpleMongoDbFactory.java:163) 〜[spring-data-mongodb-2.1.0.DATAMONGO-1920-SNAPSHOT.jar:2.1.0.DATAMONGO-1920-SNAPSHOT]

com.mongodb.MongoClientException: Sessions are not supported by the MongoDB cluster to which this client is connected at com.mongodb.MongoClient.startSession(MongoClient.java:555) ~[mongodb-driver-3.8.0-beta2.jar:na] at org.springframework.data.mongodb.core.SimpleMongoDbFactory.getSession(SimpleMongoDbFactory.java:163) ~[spring-data-mongodb-2.1.0.DATAMONGO-1920-SNAPSHOT.jar:2.1.0.DATAMONGO-1920-SNAPSHOT]

推荐答案

当我尝试将其连接到单个独立的mongo实例时,我遇到了同样的问题,但是如

I was having the same issue when I was trying to connect it to a single standalone mongo instance, however as written in the official documentation, that Mongo supports transaction feature for a replica set. So, I then tried to create a replica set with all instances on MongoDB 4.0.0, I was able to successfully execute the code. So, Start a replica set (3 members), then try to execute the code, the issue will be resolved.

注意:您可以在同一台计算机上配置副本集以进行测试

NB : you can configure a replica set on the same machine for tests https://docs.mongodb.com/manual/tutorial/deploy-replica-set-for-testing/

这篇关于如何配置支持会话的MongoDB集群?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆