
//
//

package mongodb

import scala.io.Source
import com.mongodb._
import com.osinka.mongodb._
import com.osinka.mongodb.Preamble._
import com.osinka.mongodb.shape._


object searchZip {
    val DB_PORT = 27017
    val DB_NAME = "test"
    val COLLECTION_NAME = "zipcodes"

    def main(args: Array[String]) {

        val stat=System.nanoTime()
        action()
        val end = System.nanoTime
        println("time(s):" + 1.0 * (end - stat) /(1000 * 1000 * 1000) )
    }

    def action():Unit = {

        val mongo = new Mongo("localhost", DB_PORT).getDB(DB_NAME)
        // Suppose we have a DBCollection:
        val dbColl = mongo.getCollection(COLLECTION_NAME)
        val zipcodes = dbColl.asScala

        //(Query(Map("zip" -> "1000001")) in zipcodes) foreach {x => println(x)}
        (Query(Map("addr3" -> "千代田")) in zipcodes) foreach {x => println(x)}
    }
}
