mongodb - Casbah - parametric find or findOne do not return what is there -


i have problem described in title.

for example, if try:

  val key = "mykey"   val value = "myval"    val 1 = option(collection.findone(mongodbobject(key -> value)))   val = collection.find(mongodbobject(key -> value)) 

then check contents and:

  println(one)        =>    none   println(all.size)   =>    0 

however, if not use mongodbobject parameter, works - finds stuff there.

what doing wrong? assume parameter object specifies key-value criteria should make search return results contain key-value pairs...

and have key , value valid. value, however, numeric, in stringified these statements, should no problem. or not?

update:

while trying capture data necessary more precised description of problem, have run tests sufficient realize origin of problem. turns out casbah not leave "1" remain string, automatically casts integer, , thus, comparing string integer, surely never returns true. ok, can think of solving problem this:

def getobjectby(key: string, value: string) = {   val = collection.find()   val buffer = buffer[dbobject]()   while(all.hasnext) { buffer += all.next }   val havethekey = buffer.filter(_.keyset.contains(key))    if(havethekey.size > 0) {     val 1 = havethekey(0)     val v = one.get(key)      // 1st way (hell)     v match {       case i: int => if(i == value.toint) some(one)       case s: string => if(s == value) some(one)       case f: float => if(s == value.tofloat) some(one)       //... , on..       case _ => none     }      // 2nd way (better?)     if(v.tostring == value) some(one) else none    } else none  } 

but rediculous... suppose, don't here, please tell me, missing?

ok, came sort of solution. in situation, values can either decendants of anyval or java.lang.string. common parent any. why have changed passed value type any:

def getobjectby(key: string, value: any) = {   // ... } 

and worked indeed! doh, easy! never used object in java or any in scala, , did not think work that... but..


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -