Version 3, last updated by eltimn at 25 Feb 02:39 UTC
Mongo Low Level Operations
These are mostly used by the other library classes, but can be used directly if needed. See MongoDirectSpec.scala for examples.
Use a db:
MongoDB.use(DefaultMongoIdentifier) { db =>
val doc = new BasicDBObject
doc.put("name", "MongoDB")
doc.put("type", "database")
doc.put("count", 1)
val coll = db.getCollection("testCollection")
// save the doc to the db
coll.save(doc)
}
Use a collection:
MongoDB.useCollection(collectionName) { coll =>
val doc = new BasicDBObject
doc.put("name", "MongoDB")
doc.put("type", "database")
doc.put("count", 1)
// save the doc to the db
coll.save(doc)
}
Use a single thread for all operations:
MongoDB.useSession { db =>
val coll = db.getCollection("testCollection")
val doc = new BasicDBObject
doc.put("name", "MongoSession")
doc.put("type", "db")
doc.put("count", 1)
coll.save(doc)
db.getLastError
...
}