我用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
展开
 我来答
匿名用户
2015-08-27
展开全部
documents.put("name", "abc") ;
documents.put("age", 24) ;

检查你的json数据中是否包含这些key
追问
奥,多谢,现已解决,我的driver包版本高了,下了一个版本低一点的好了、
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式