Last active
December 24, 2015 07:19
-
-
Save kevinmeredith/6763397 to your computer and use it in GitHub Desktop.
Problem when trying to bulk insert in Casbah
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // recurse through each element of "docs", using `builder` to add another key-value MongoDBObject for time-stamp purposes | |
| def getEnrichedDocs(docs: List[DBObject]) : List[DBObject] = { | |
| def go(list : List[DBObject], docs_: List[DBObject]) : List[DBObject] = list match { | |
| case x :: xs => var builder = MongoDBObject() | |
| builder = builder ++ MongoDBObject("LoadTimestamp" -> Utils.getTimestamp) // returns a Long (I know that I should be using a BSON TS, but that's a TODO | |
| builder = builder ++ x | |
| go(xs, docs_ :+ builder) // call go() recursively with the updated accumulator (2nd arg) | |
| case Nil => docs_ | |
| } | |
| go(docs, List[DBObject]()) | |
| } | |
| val allDocs: List[DBObject] = getEnrichedDocs(getDocsList()) // getDocsList() unspecified here sincecontent not imp here | |
| // Bulk insert | |
| val docsList = MongoDBList(allDocs: _*) // avoid using a List of lists | |
| collection.insert(docsList) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also posted here - http://stackoverflow.com/questions/19058990/java-lang-illegalargumentexception-basicbsonlist-can-only-work-with-numeric-key