At first glance, things look OK in the code, although you have this wandering code def addMongo(): Unit = {
at the top. I put off the suggestion of finding errors here ... Two notes:
1) save()and insert()are additional operations - you only need one. insert()will always try to create a new document ... save()will create it if the field is _idnot set and will update the submitted _idif this happens.
2) Mongo . , MongoDB , . getLastError() . Java MongoDB , , , "" (, ). Java- ( Scala, , ):
mongo.requestStart() // lock the connection in
coll.insert(obj) // attempt the insert
getLastError.throwOnError() // This tells the getLastError command to throw an exception in case of an error
mongo.requestDone() // release the connection lock
MongoDB Write Durability, Java.
Scala , (Casbah), Java scala.
, , (), .