简体   繁体   English

MongoDB Java / Scala驱动程序-缺少方法

[英]MongoDB Java / Scala drivers - Missing methods

I'm trying to convert a persistence layer from a plain old database (using ScalaQuery) to MongoDB, and I'm running into an odd issue. 我试图将一个持久层从一个普通的旧数据库(使用ScalaQuery)转换为MongoDB,但遇到一个奇怪的问题。 I use the Casbah driver, which is a Scala wrapper around the official MongoDB Java driver. 我使用Casbah驱动程序,它是官方MongoDB Java驱动程序的Scala包装器。 Both the Java and Scala driver define - according to the docs and the overview of the .jar when I open it in Eclipse - a method findOneById that takes a single DBObject as parameter (with an ID in it). Java和Scala驱动程序均定义-根据文档以及当我在Eclipse中打开.jar时的概述-一种使用单个DBObject作为参数(其中带有ID)的findOneById方法。

However, when I try to access it, I get a missing method exception from the Scala compiler, both in Eclipse and SBT - Scala version 2.9.0-1, SBT 0.10.1. 但是,当我尝试访问它时,在Eclipse和SBT中,Scala编译器都丢失了一个方法异常-Scala版本2.9.0-1,SBT 0.10.1。

What might cause this? 是什么原因造成的? Is this perhaps a known SBT / Scala compiler bug? 这可能是已知的SBT / Scala编译器错误吗?

I just removed my entire repository so all dependencies get downloaded freshly, but this didn't fix the problems. 我只是删除了整个存储库,所以所有依赖项都可以重新下载,但这并不能解决问题。

Are you sure that you call findOneById on a MongoCollection instance ? 您确定在MongoCollection实例上调用findOneById吗?

Maybe it's the parameter type that is wrong, as I can see on the documentation (http://api.mongodb.org/scala/casbah/2.1.2/scaladoc/com/mongodb/casbah/MongoCollection.html), findOneById should take an Id of type AnyRef and optionnaly the fields to return. 也许是错误的参数类型,正如我在文档(http://api.mongodb.org/scala/casbah/2.1.2/scaladoc/com/mongodb/casbah/MongoCollection.html)上看到的那样, findOneById应该接受类型为AnyRef的ID,然后选择要返回的字段。

You should try something like mongoCollection.findOneByID(1.asInstanceOf[Object]) . 您应该尝试使用诸如mongoCollection.findOneByID(1.asInstanceOf[Object])

Regarding BBObject , it seems that it doesn't appear in the list of parameter (except as an implicit parameter useful to convert the fields that you request to a DBObject ). 关于BBObject ,它似乎没有出现在参数列表中(除了作为将您请求的字段转换为DBObject的隐式参数DBObject )。 Maybe the signature of the method changed since a previous release. 自上一发行版以来,方法的签名可能已更改。

Hope this will help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM