我将一个简单的数据结构(下面引用的Transaction
)插入到mongodb中:
{"amount":111,"debitAcc":"588188286231743e7d5c923d","type":"CHARGE"}
我得到了以下错误堆栈:
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
at com.mongodb.connection.SocketStream.read(SocketStream.java:88)
at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:494)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:224)
at com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:96)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:440)
at com.mongodb.connection.WriteCommandProtocol.receiveMessage(WriteCommandProtocol.java:262)
at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:104)
at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:67)
at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
at com.mongodb.connection.DefaultServerConnection.insertCommand(DefaultServerConnection.java:118)
at com.mongodb.operation.InsertOperation.executeCommandProtocol(InsertOperation.java:76)
at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:139)
at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:133)
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:422)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:413)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:133)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:60)
at com.mongodb.Mongo.execute(Mongo.java:845)
at com.mongodb.Mongo$2.execute(Mongo.java:828)
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:342)
at com.mongodb.DBCollection.insert(DBCollection.java:337)
at com.mongodb.DBCollection.insert(DBCollection.java:328)
at org.mongodb.morphia.DatastoreImpl.saveDocument(DatastoreImpl.java:1297)
at org.mongodb.morphia.DatastoreImpl.tryVersionedUpdate(DatastoreImpl.java:1340)
at org.mongodb.morphia.DatastoreImpl.save(DatastoreImpl.java:1286)
at org.mongodb.morphia.DatastoreImpl.save(DatastoreImpl.java:775)
at org.mongodb.morphia.DatastoreImpl.save(DatastoreImpl.java:758)
我的mongodb版本是3.4.2
。
相互关系是我在本地开发环境中没有问题(mint linux 18.1)。但它只能在我的SIT环境中工作,这是一个ubuntu 16.04
有什么想法吗?
使用代码更新以插入文档
可以在以下位置找到transactionDao.save(...)
实施位置:
更新2
系统可以与其他写入一起使用(即使记录更大)
答案 0 :(得分:7)
大多数情况下,这是由于长读/写的超时造成的。
尝试增加超时或完全删除它们:
MongoClientOptions.Builder options_builder = new MongoClientOptions.Builder();
options_builder.maxConnectionIdleTime(<some_long_time>);
MongoClientOptions options = options_builder.build();
MongoClient mongo_db = new MongoClient ("your.db.address", options);
答案 1 :(得分:2)
我没有根本原因,但最后我通过将字段类型从BigDecimal
更改为double
来解决问题。
问题出现在我们的SIT环境和一个开发人员的Windows环境中,它有一个mongodb cluser设置。
答案 2 :(得分:2)
最可能的原因是兼容性版本设置得太低。
尝试db.adminCommand({setFeatureCompatibilityVersion:&#34; 3.4&#34;})
https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/