/src/test/scala/org/jcheng/CasbahDemo.scala

https://github.com/jlcheng/hello-finagle · Scala · 45 lines · 27 code · 14 blank · 4 comment · 0 complexity · 30128ad24eeffa40996e4450befd3e61 MD5 · raw file

  1. package org.jcheng
  2. import com.mongodb.casbah.MongoConnection
  3. import com.mongodb.casbah.commons.MongoDBObject
  4. import com.mongodb.casbah.commons.conversions._
  5. import com.mongodb.casbah.Imports._
  6. /**
  7. * @author jcheng
  8. *
  9. */
  10. object CasbahDemo {
  11. def main(argv: Array[String]) {
  12. val testData = MongoConnection()("jctest")("testdata")
  13. println("Assuming this is not the first run...")
  14. println("Size should be 2: " + testData.size)
  15. testData.remove(MongoDBObject("name" -> "firs"))
  16. println("Size should be 1: " + testData.size)
  17. testData.remove(MongoDBObject()) // remove everything
  18. testData += MongoDBObject("name" -> "first", "val"-> 1)
  19. testData += MongoDBObject("name" -> "second", "val"-> 2)
  20. val objA = MongoDBObject("name" -> "third", "val" -> 3)
  21. println("Should be 'third': " + objA.getAs[String]("name"))
  22. testData += objA
  23. testData.findOne(MongoDBObject("name" -> "third"), MongoDBObject("val"->1)).foreach { x =>
  24. println(x)
  25. }
  26. testData += MongoDBObject("name" -> "four", "val" -> 4, "email" -> "foo@example.com")
  27. println( testData.findOne("email" $exists true).get )
  28. testData.update(MongoDBObject("name" -> "four"), $set ("email" -> "bar@example.com"))
  29. println( testData.findOne("email" $exists true).get )
  30. }
  31. }