Starting out with mongo-scala-driver

16 views
Skip to first unread message

Ilkka Huotari

unread,
Nov 5, 2010, 11:24:51 PM11/5/10
to mongo-scala-driver
Hi,

I'm new so first comes a newbie question. Sorry about it.

Is there a wiki page/instructions for the first steps with mongo-scala-
driver? By first steps I mean:
- What classes to import.
- How to connect to MondoDB (database connection).
- Maybe some best practices - where to do that connection/what objects
to create for it/etc/whatever you can think of that might help a
newbie :) I'm using Play framework at the moment, so if there is any
specific things for that, it would interest of course. Generally
speaking; how to use with frameworks. (I'm not sure if this point is
important at all but throwing it in there in case it makes sense).

Thanks.

Alexander Azarov

unread,
Nov 6, 2010, 5:39:21 PM11/6/10
to mongod...@googlegroups.com
Hi,

06.11.2010, в 6:24, Ilkka Huotari wrote:

> Hi,
>
> I'm new so first comes a newbie question. Sorry about it.
>
> Is there a wiki page/instructions for the first steps with mongo-scala-
> driver? By first steps I mean:
> - What classes to import.

import com.osinka.mongodb._
import com.osinka.mongodb.shape._

> - How to connect to MondoDB (database connection).

Via Java MongoDB driver: http://api.mongodb.org/java/2.3/

mongo-scala-driver is a wrapper around MongoDB Java driver, so basically you need to get an instance from Java driver and then lift it to Scala instance:

val db = mongo.getDB("mydb")
val dbCollection = db.getCollection("my_objects")
val myObjects = dboCollection of MyObjectShape

> - Maybe some best practices - where to do that connection/what objects
> to create for it/etc/whatever you can think of that might help a
> newbie :) I'm using Play framework at the moment, so if there is any

Mongo Java driver manages connection pool internally, so you can safely have a singleton "database" object and get Collection instances when you want. Or you may have Collection singletons as well.

Ilkka Huotari

unread,
Nov 9, 2010, 7:13:35 PM11/9/10
to mongo-scala-driver
Thank you, those helped.
Reply all
Reply to author
Forward
0 new messages