Wiki
Clone wikiMoScale / Home
MoScale
MoScale is a Scala toolkit library for MongoDB. It uses official mongo-java-driver to access MongoDB and provide fancy and typesafe way to manipulate objects.
Authors
- Andrey Feoktistov — cattum@gmail.com
- Alexey Karapoltsev — alexey.kardapoltsev@gmail.com
Main contributors
- Anjey Katkov — anjey.katkov@frumatic.com
- Sergey Chebotar — serge.cheebo@gmail.com
Example
#!scala package mypkg import com.codebranch.scala.mongodb._ import com.codebranch.scala.mongodb.handlers._ import org.bson.types.ObjectId import org.joda.time.DateTime import me.selfish.iapi.common.data.FileMetadata @CollectionEntity(databaseName = "mls", collectionName = "S3File") class S3File extends Entity with EntityId { import S3File.{Field => F, _} /** S3 bucket name. */ val s3Bucket = Field[String](F.S3Bucket) /** S3 key (file name) */ val s3Key = Field[String](F.S3Key) /** All tags associated with this file */ val tags = Field[List[String]](F.Tags, Some(Nil)) /** Status of the file. */ val status = Field[Status.Value](F.Status, Some(Status.New)) } object S3File extends CollectionObject[S3File] { object Status extends Enumeration { val New = Value("New") val Uploaded = Value("Uploaded") val Processed = Value("Processed") val Verified = Value("Verified") val Blocked = Value("Blocked") val Deleted = Value("Deleted") } object Field { val S3Bucket = "s3Bucket" val S3Key = "s3Key" val Tags = "tags" val Status = "status" } override def init()(implicit mongo: MongoClient) { import Field._ super.init() ensureIndex(Status) ensureIndex(Tags) } } object Main { import S3File._ def main(args : Array[String]) { val o = new S3File o.bucketName := "test" o.key := "filename.jpeg" o.status := Status.New o.tags := List("tag1", "tag2") S3File.save(o) S3File.find(Query("bucket" -> in("bucket1", "bucket2"))).foreach { obj => //process object } } }
Updated