Skip to content

loewenstein/mongo-scala-driver

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scala wrapper for MongoDB

mongo-scala-driver is a thin wrapper around mongo-java-driver to make working with MongoDB more Scala-like.

The first of all, this is a work in progress and implements only a subset of MongoDB features at the moment.

Wiki
Mailing list

Important changes

Version 0.8.5

  • Bug fix: Related operations are executed via the same database connection

Version 0.8.4

  • Mongo Java driver 2.1
  • batchInsert support
  • findAndRemove support
  • findAndModify support

Version 0.8.3

  • remove operation now supports queries.

Version 0.8.2

Version 0.8.0

  • mongo-java-driver 1.4
  • OSGi-fied
  • Simple Build Tool (SBT) support

Incompatible changes:

  • Preamble replaced by Scala 2.8 “package object”: no need to import @Preamble@s

Version 0.7.4

  • mongo-java-driver 1.3 compatibility
  • Map field

Version 0.7.2

Version 0.7.1

  • mongo-java-driver 1.2 compatibility

Version 0.7

The major goal of 0.7 is to cover whole set of MongoDB’s document data types. The release introduces arrays and references as well as consistent architecture to combine Mongo data types along with Scala models to represent:

  • complex objects inside a document
  • Ref[T] fields, i.e.
    • references to objects inside a document
  • Option[T] fields, i.e.
    • optional simple values inside a document
    • optional complex objects inside a document
  • Array[T] fields, i.e.
    • arrays of simple values inside a document
    • arrays of references inside a document

The release works out the following issues also:

  • mongo-java-driver version 1.1

Some of these changes required a major refactoring of Shape/Field code which led to a number of breaking changes. The following list summarizes most important incompatible changes.

MongoCollection is a PartialFunction

MongoCollection (as well as ShapedCollection) are PartialFunction[ObjectId, T] now. This means you can request an object by its ID natually or test for existance.

MongoObject fields are Option’s

MongoObject is a trait to mix it into a classes of object you are going to store in MongoDB and it declares a couple of MongoDB related fields: OID and ns. Both of these fields are now Option, so you will have to modify your code in case you used them

Field descriptor constructors

You used to construct fields in Shapes as objects inheriting Scalar or Embedded classes. These were removed, so you may use either ScalarField, OptionalField and EmbeddedField classes to inherit or Field.scalar, Field.optional methods:

object SomeShape extends ObjectShape[SomeObj] {
  val idField = Field.scalar("id", _.id) // OR
  object idField extends ScalarField[Int]("id", _.id) with Functional[Int]

  val statusField = Field.optional("status", _.status) // OR
  object statusField extends OptionalField[Int]("status", _.status) // NOTE SomeObj.status method returns Option[Int]
}

ShapeFields

You used to inherit ShapeFields in Shapes of child objects, when constructing complex hierarchies. Now you should inherit ObjectIn instead.

About

Working with MongoDB in a Scala way

Resources

License

Stars

Watchers

Forks

Packages

No packages published