在 casbah 的 find() 查询中使用 $in
我正在尝试在 find() 中使用 casbah 的流体查询。
我的数据是这样的:
{ "_id" : ObjectId("4d7b26efc58bf2b18f14d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06sfnt9" ] }
{ "_id" : ObjectId("4d7b26efc58bf2b19014d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06fqp8" ] }
{ "_id" : ObjectId("4d7b26efc58bf2b19114d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06_7xfd" ] }
我写了下面的代码来查询这个:
val srcIDs:List[String] = List("/m/05zppz", "/m/06sfnt9")
val query = "srcID" $in srcIDs
代码段没有编译并报告这个错误:
error: value $in is not a member of java.lang.String
query = ("srcID" $in srcIDs)
casbah文档有$in的上述语法,但它似乎不起作用。 如何使 $in 查询工作?事实上,我无法使用 Casbah 的 DSL 进行任何流畅的查询,并且它们无法给出相同的错误消息。请帮忙!
I'm trying to use casbah's fluid querying in find().
My data is like this:
{ "_id" : ObjectId("4d7b26efc58bf2b18f14d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06sfnt9" ] }
{ "_id" : ObjectId("4d7b26efc58bf2b19014d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06fqp8" ] }
{ "_id" : ObjectId("4d7b26efc58bf2b19114d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06_7xfd" ] }
I wrote the following code to query this:
val srcIDs:List[String] = List("/m/05zppz", "/m/06sfnt9")
val query = "srcID" $in srcIDs
the code segment does not compile and reports this error:
error: value $in is not a member of java.lang.String
query = ("srcID" $in srcIDs)
The casbah documentation has the above syntax for $in, but it doesn't seem to work.
How to make the $in query work? As a matter of fact, I could not get any fluid query with Casbah's DSL to work and they fail giving the same error msg. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是
$in
不是在字符串上定义的方法。 Casbah 很可能定义了从String
对象到包含方法$in
的类实例的隐式转换。隐式转换需要先导入
到作用域中,然后才能使用。您能给我们指出介绍
$in
方法的 Casbah 文档吗?我们将在那里找到需要导入的内容。(对于专家来说:
$
不应该保留给编译器生成的字段吗?)The problem is that
$in
is not a method defined on strings. Most likely Casbah defines an implicit conversion fromString
objects to instances of a class that contain the method$in
. The implicit conversion needs to beimport
ed into scope before it can be used.Could you point us to the Casbah documentation that introduces the
$in
method? That's where we will find what needs to be imported.(For the experts: isn't
$
supposed to be reserved for compiler generated fields?)我修好了!你的回复非常有帮助。我错过了隐式转换所需的导入语句,因此它将其视为字符串。
我添加了
import com.mongodb.casbah.Imports._
,它现在就像一个魅力。谢谢你的提示!I fixed it! You reply was very helpful. I had missed the import statement needed for implicit conversion and hence it was treating it as a String.
I included
import com.mongodb.casbah.Imports._
and it works like a charm now. Thanks for the hint!