-
-
Save hanrw/fd098cf0c2f135965469 to your computer and use it in GitHub Desktop.
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
case class Account(name:String, username:String, password:String) |
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
object App { | |
def main(args:Array[String]) = { | |
val ctx: ApplicationContext = new AnnotationConfigApplicationContext(classOf[MongoConfig]) | |
val mongoOperations: MongoOperations = ctx.getBean("mongoTemplate").asInstanceOf[MongoOperations] | |
} | |
} |
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
name := "SpringMongo" | |
version := "1.0" | |
scalaVersion := "2.9.1" | |
resolvers += "Spring Maven MILESTONE Repository" at "http://maven.springframework.org/milestone" | |
libraryDependencies ++= Seq( | |
"org.mongodb" % "mongo-java-driver" % "2.6", | |
"org.springframework" % "spring-core" % "3.0.5.RELEASE", | |
"org.springframework" % "spring-context" % "3.0.5.RELEASE", | |
"org.springframework.data" % "spring-data-mongodb" % "1.0.0.M4", | |
"cglib" % "cglib" % "2.2" | |
) |
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
@Configuration | |
class MongoConfig extends AbstractMongoConfiguration { | |
def getDatabaseName:String = "mydb" | |
def mongo:Mongo = new Mongo("localhost") | |
} |
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
import collection.JavaConversions._ | |
val results = mongoOperations.find( | |
new Query(Criteria where("name") is("Amir Moulavi")), classOf[Account], "accounts") | |
results.foreach(println) |
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
val account = Account("Amir Moulavi", "amirmoulavi", "123456") | |
mongoOperations.save(account, "accounts") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment