我用java连接mongodb抛出如下错,哪位大神见过??求帮忙。。 5
publicstaticvoidmain(String[]args){//Mongom=newMongo();DBdb=MongoUtils.getDB("test");...
public static void main(String[] args) {
// Mongo m = new Mongo();
DB db = MongoUtils.getDB("test") ;
DBCollection coll = db.getCollection("mycollection") ;
DBObject documents = new BasicDBObject();
documents.put("name", "abc") ;
documents.put("age", 24) ;
coll.insert(documents) ;
}
之后抛出此错误:
com.mongodb.MongoException: org.bson.BsonInvalidOperationException: Document does not contain key versionArray
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:112)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.bson.BsonInvalidOperationException: Document does not contain key versionArray
at org.bson.BsonDocument.throwIfKeyAbsent(BsonDocument.java:757)
at org.bson.BsonDocument.getArray(BsonDocument.java:140)
at com.mongodb.connection.DescriptionHelper.getVersion(DescriptionHelper.java:106)
at com.mongodb.connection.DescriptionHelper.createConnectionDescription(DescriptionHelper.java:56)
at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:85)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:43)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:98)
... 2 more 展开
// Mongo m = new Mongo();
DB db = MongoUtils.getDB("test") ;
DBCollection coll = db.getCollection("mycollection") ;
DBObject documents = new BasicDBObject();
documents.put("name", "abc") ;
documents.put("age", 24) ;
coll.insert(documents) ;
}
之后抛出此错误:
com.mongodb.MongoException: org.bson.BsonInvalidOperationException: Document does not contain key versionArray
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:112)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:127)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.bson.BsonInvalidOperationException: Document does not contain key versionArray
at org.bson.BsonDocument.throwIfKeyAbsent(BsonDocument.java:757)
at org.bson.BsonDocument.getArray(BsonDocument.java:140)
at com.mongodb.connection.DescriptionHelper.getVersion(DescriptionHelper.java:106)
at com.mongodb.connection.DescriptionHelper.createConnectionDescription(DescriptionHelper.java:56)
at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:85)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:43)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:98)
... 2 more 展开
1个回答
2015-08-27
展开全部
documents.put("name", "abc") ;
documents.put("age", 24) ;
检查你的json数据中是否包含这些key
documents.put("age", 24) ;
检查你的json数据中是否包含这些key
追问
奥,多谢,现已解决,我的driver包版本高了,下了一个版本低一点的好了、
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询