Created
October 6, 2010 00:09
-
-
Save tc/612584 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mongodb.{Mongo, DB, DBObject} | |
import com.mongodb.util.JSON | |
import org.junit.{Assert, Test} | |
/** | |
* | |
* User: @tommychheng | |
* Date: Sep 24, 2010 | |
* Time: 9:36:41 AM | |
* | |
* | |
*/ | |
class MongoTest{ | |
@Test | |
def testInsertJSQuery{ | |
val m = new Mongo() | |
val db = m.getDB("test") | |
val collection = db.getCollection("test_data") | |
collection.drop() //make sure the collection is empty | |
val document = """ {"foo": "bar", "age": 5} """ | |
val documentObject = JSON.parse(document).asInstanceOf[DBObject] | |
collection.insert(documentObject) | |
val query = """ {"foo": "bar"} """ | |
val queryObject = JSON.parse(query).asInstanceOf[DBObject] | |
val cursor = collection.find(queryObject).iterator | |
while(cursor.hasNext){ | |
val item = cursor.next | |
Assert.assertEquals("bar", item.get("foo")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment