Created
July 30, 2012 12:48
-
-
Save rktoomey/3206677 to your computer and use it in GitHub Desktop.
Updating with SalatDAO
This file contains hidden or 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
scala> import model._ | |
import model._ | |
scala> import org.bson.types.ObjectId | |
import org.bson.types.ObjectId | |
scala> import com.mongodb.casbah.Imports._ | |
import com.mongodb.casbah.Imports._ | |
scala> val _id = new ObjectId | |
_id: org.bson.types.ObjectId = 50167fbee4b036019b42a0e4 | |
scala> val f = Foo(_id = _id, x = "Test", counter = 1) | |
f: model.Foo = Foo(50167fbee4b036019b42a0e4,Test,1) | |
scala> FooDAO.insert(f) | |
res0: Option[org.bson.types.ObjectId] = Some(50167fbee4b036019b42a0e4) | |
scala> FooDAO.update(q = MongoDBObject("_id" -> _id), o = MongoDBObject("$set" -> MongoDBObject("x" -> "Test2")), upsert = false, multi = false) | |
scala> FooDAO.findOneById(_id) | |
res4: Option[model.Foo] = Some(Foo(50167fbee4b036019b42a0e4,Test2,1)) | |
scala> FooDAO.update(q = MongoDBObject("_id" -> _id), o = MongoDBObject("$inc" -> MongoDBObject("counter" -> 1)), upsert = false, multi = false) | |
scala> FooDAO.findOneById(_id) | |
res7: Option[model.Foo] = Some(Foo(50167fbee4b036019b42a0e4,Test2,2)) | |
scala> FooDAO.update(MongoDBObject("_id" -> _id), MongoDBObject("$inc" -> MongoDBObject("counter" -> 1)), false, false) | |
scala> FooDAO.findOneById(_id) | |
res9: Option[model.Foo] = Some(Foo(50167fbee4b036019b42a0e4,Test2,3)) |
This file contains hidden or 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
package model | |
import org.bson.types.ObjectId | |
import com.novus.salat.global._ | |
import com.novus.salat.dao.SalatDAO | |
import com.mongodb.casbah.MongoConnection | |
case class Foo(_id: ObjectId, x: String, counter: Int) | |
object FooDAO extends SalatDAO[Foo, ObjectId](collection = MongoConnection()("test_db")("foo")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment