English 中文(简体)
• 如何为reg鱼的配对点查询。
原标题:How to query a Array[String] for a regexp match?

i 试图通过Casbah对MongoDB进行实地调查,这个领域是一系列带有reg的扼杀。

例如:

I have a Maschine with a list of ips, that are stored as string in the fields ips. Now i want to search for all machines that have the subnet 192.168.

对我来说,如果一个条目与机器相匹配,则不能问一阵列,每个条目都适用了reg。

作出这种质疑的任何方法?

页: 1

感谢您的帮助。

现在一切都奏效。 最后,我需要围绕卡巴的一个限制开展工作,因为我需要与 $和 Cas一道,就reg中缺失的暗含物提出申诉。

我关于“Refp Array”问题的最后守则是:

val regexp = ".*" + parameter + ".*"
val nameQ = MongoDBObject("serverName" -> regexp.r)
val ipsQ = MongoDBObject("ips" -> regexp.r)
val bldr = MongoDBList.newBuilder
bldr += ipsQ
bldr += nameQ
val query = MongoDBObject("$or" -> bldr.result.asDBObject)
val result = find(query)

It is not the nicest code and the string concatenation of the parameter needs to be fixed. But it works :)

最佳回答

You can ignore the fact that this is an array:

> db.rx.insert( { "ips" : ["192.168.1.231", "192.168.2.231", "120.32.42.51"] });
> db.rx.find( { ips : /192./ } )
{ "_id" : ObjectId("4f104f0183bfca7a48b60da1"), 
  "ips" : [ "192.168.1.231", "192.168.2.231", "120.32.42.51" ] }

Mongo 亚洲开发银行始终如一:如果你对待像正常领域一样的阵列,它将对每个成员适用这一行动,如果对口,则认为母体文件相匹配。

问题回答




相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签