scala – java.lang.IllegalArgumentException:BasicBSONList只
发布时间:2020-12-16 18:12:22 所属栏目:安全 来源:网络整理
导读:又一个SO海报(Vinicius Miana)解决了我的 issue插入List [DBObject] … // Bulk insert all documentscollection.insert(MongoDBList(docs)) // docs is List[DBObject] 现在,我在尝试插入时看到了这个错误. java.lang.IllegalArgumentException:BasicBSONL
又一个SO海报(Vinicius Miana)解决了我的
issue插入List [DBObject] …
// Bulk insert all documents collection.insert(MongoDBList(docs)) // docs is List[DBObject] 现在,我在尝试插入时看到了这个错误. java.lang.IllegalArgumentException:BasicBSONList只能使用数字键,而不是:[_ id] 编辑 完整堆栈跟踪 [info] java.lang.IllegalArgumentException: BasicBSONList can only work with numeric keys,not: [_id] [info] at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:161) [info] at org.bson.types.BasicBSONList._getInt(BasicBSONList.java:152) [info] at org.bson.types.BasicBSONList.get(BasicBSONList.java:104) [info] at com.mongodb.DBCollection.apply(DBCollection.java:767) [info] at com.mongodb.DBCollection.apply(DBCollection.java:756) [info] at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:220) [info] at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204) [info] at com.mongodb.DBCollection.insert(DBCollection.java:76) [info] at com.mongodb.casbah.MongoCollectionBase$class.insert(MongoCollection.scala:508) [info] at com.mongodb.casbah.MongoCollection.insert(MongoCollection.scala:866) 我已经检查了一个post与我完全相同的问题,但我不知道如何应用接受的答案. 这个错误是否意味着我不能插入任何键值对,使得值不能转换为Int(每BasicBSONList)? 解决方法
MongoDBList与普通列表不同,它是BasicDBList的便利包装器,因此转换为vargs不能按预期工作.
你应该提供List [DBObject],然后爆炸成vargs: val docs = List[DBObject("a" -> "b") collection.insert(docs: _*) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |