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

查看:26
本文介绍了如何配置支持会话的 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.

堆栈跟踪开始于:

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 实例时遇到了同样的问题,但是正如 官方文档,Mongo支持副本集的事务功能.所以,然后我尝试在 MongoDB 4.0.0 上创建一个包含所有实例的副本集,我能够成功执行代码.所以,启动一个副本集(3个成员),然后尝试执行代码,问题就解决了.

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.

注意:您可以在同一台机器上配置副本集进行测试 https://docs.mongodb.com/manual/tutorial/deploy-replica-set-for-testing/

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天全站免登陆