January 2016
Intermediate to advanced
416 pages
8h 54m
English
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 ...
Read now
Unlock full access