Inserting documents

Let's insert some documents into our newly created database. We want to store information about GitHub users, using the following document structure:

{
    id: <mongodb object id>,
    login: "pbugnion",
    github_id: 1392879,
    repos: [ 
        {
            name: "scikit-monaco",
            id: 14821551,
            language: "Python"
        },
        {
            name: "contactpp",
            id: 20448325,
            language: "Python"
        }
    ]
}

Casbah provides a DBObject class to represent MongoDB documents (and subdocuments) in Scala. Let's start by creating a DBObject instance for each repository subdocument:

scala> val repo1 = DBObject("name" -> "scikit-monaco", "id" -> 14821551, "language" -> "Python")
repo1: DBObject = { "name" : "scikit-monaco" , "id" : 14821551, "language" : "Python"}

As you can see, a DBObject is just ...

Get Scala:Applied Machine Learning now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.