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.