在 casbah 的 find() 查询中使用 $in

发布于 2024-11-28 07:02:54 字数 935 浏览 3 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

≈。彩虹 2024-12-05 07:02:54

问题是 $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 from String objects to instances of a class that contain the method $in. The implicit conversion needs to be imported 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?)

帅哥哥的热头脑 2024-12-05 07:02:54

我修好了!你的回复非常有帮助。我错过了隐式转换所需的导入语句,因此它将其视为字符串。

我添加了 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文