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.
- Bug fix: Related operations are executed via the same database connection
- Mongo Java driver 2.1
batchInsert
supportfindAndRemove
supportfindAndModify
support
remove
operation now supports queries.
- Issue 43 fixed
- Scala 2.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
- mongo-java-driver 1.3 compatibility
- Map field
- Modifier operations on object fields (see MongoDB: Updating)
- mongo-java-driver 1.2 compatibility
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
(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
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
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]
}
You used to inherit ShapeFields
in Shapes of child objects, when constructing complex hierarchies. Now you should inherit ObjectIn
instead.