MongoSocketReadException: Prematurely reached end of stream (after a period of inactivity)

前端 未结 6 1920
Happy的楠姐
Happy的楠姐 2020-12-05 02:34

I get this error on a find call (default Java Driver) after a period of inactivity. I tried to add a manual heartbeat (writing to a capped collection), but it d

6条回答
  •  爱一瞬间的悲伤
    2020-12-05 03:37

    This worked for me in spring boot and cloud based mongo (Atlas clustered instances).

    Edit application.properties like this:

    spring.data.mongodb.uri = mongodb+srv://username:password@solarsystem-1tpu0.mongodb.net/dbname
    

    For regular mongo instances (non-clustered) use this:

    spring.data.mongodb.uri = mongodb://username:password@solarsystem-shard-00-00-1tpu0.mongodb.net:27017,hostname2:27017/dbname?ssl=true
    
    • If you want to set other connection options, you can chain multiple parameters using '&' ; documentation here: https://mongodb.github.io/mongo-java-driver/3.4/javadoc/com/mongodb/MongoClientURI.html
    • If you were using other spring.data.mongodb parameters, you should remove all of them otherwise spring won't read spring.data.mongodb.uri

提交回复
热议问题