SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
Scala with MongoDB

Abdhesh Kumar
Email: abdhesh@knoldus.com
Twitter:@abdheshkumar90
Agenda
1. What is MongoDB?
2. Why we use MongoDB?
3. What are the MongoDB Terminologies?
4. How to Install and Use MonogDB?
5. What are the Operators of MongoDB?
6. What is Casbah?
7. What is Salat?
What is MongoDB?
➢ MongoDB is a document-oriented database management
system designed for performance, horizontal scalability, high
availability,open source NoSQL database(Schemaless or
Non-relational) ,And advanced queryability.
➢ MongoDB is a document-based database system, and as a
result, all records, or data, in MongoDB are documents.
Why we use MongoDB?
Document Oriented
➢ Documents (objects) map nicely to programming language data
types.
➢ Dynamically-typed (schemaless) for easy schema evolution.
➢ No joins and no transactions for high performance and easy
scalability
High Performance
➢ No joins and no transactions makes reads and writes fast
➢ Indexes can include keys from embedded documents and
arrays.
➢ Optional asynchronous writes
.
High Availability
➢Replicated servers with automatic master failover.
Easy Scalability
➢ Automatic sharding distributes collection data across machines.
➢Reads and writes are distributed over shards
Flexibility
➢MongoDB stores data in JSON documents (which we serialize
to BSON).
Indexing
➢ MongoDB supports generic secondary indexes, allowing a
variety of fast queries,and provides unique, compound, and
geospatial indexing capabilities as well.
Fixed-size collections
➢ Capped collections are fixed in size and are useful for certain
types of data, such as logs.
➢ Real time aggregation
➢ Rich query capabilities
➢ Geospatial features
➢ Flexible schema
MongoDB Terminologies
Sql Terms/Concepts

MongoDB Terms/Concepts

database

database

table

collection

index

index

row

Document or *BSON document

column

Field or BSON field

join

*Embedding and linking

Primary key

_id

Group by

aggregation
MongoDB Terms/Concepts
Documents:
➢ The concept of a document: an ordered set of keys with
associated values.
➢ documents are represented as objects:
{"greeting" : "Hello, world!"}
Collections:
➢ A collection is a group of documents.
Embedding:
➢ “Embedding is the nesting of objects and arrays inside a
BSON document”
Linking:
➢ “Links are references between documents”
Aggregation:
➢ The MongoDB aggregation framework provides a means to
calculate aggregated values without having to use map-reduce.
➢ If you’re familiar with SQL, the aggregation framework
provides similar functionality to GROUP BY and related SQL
operators as well as simple forms of “self joins.” Additionally,
the aggregation framework provides projection capabilities to
reshape the returned data.
What is JSON?
➢ JSON (JavaScript Object Notation) is a lightweight
data-interchange format.
➢ JSON is built on two structures:
1. A collection of name/value pairs. ex.object, record, struct,
dictionary, hash table, keyed list, or associative array
2. An ordered list of values. ex. array, vector, list, or sequence
{
"_id" : 1,
"name" : { "first" : "Rohan", "last" : "Singh" },
"contributes" : [ "TypeSafe", "Knoldus" ],
"awards" : [
{
"award" : "Play Framework Expert",
"year" : 2012,
"by" : "TypeSafe"
},
{ "award" : "Scala Expert",
"year" : 2013,
"by" : "Knoldus"
}
]
}
What is BSON?
➢ BSON is a binary-encoded serialization of JSON-like
document.
➢ BSON supports the embedding of documents and arrays
within other documents and arrays.
➢ MongoDB uses BSON as the data storage and network
transfer format for “documets”.
Install MongoDB
$ wget
http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.0.6.tgz
$ tar -zxvf mongodb-osx-x86_64-2.0.6.tgz
$ sudo mkdir -p /data/db
$ sudo chown `id -u` /data/db
Starting MonDB and Mongo Shell
➢ $ ./bin/mongod
➢ $ mongo
MongoDB shell version: 2.4.1
connecting to: test
>
MongoDB Operators
Query Selectors:
➢ Comparison
$all, $gt, $gte, $in, $lt, $lte, $ne, $nin
➢ Logical
$and, $or, $nor, $not
➢ Element
$exists, $mod, $type
➢ JavaScript
$regix, $where
➢ Array
$elemMatch,$size

Update
➢ Fields
$inc, $set, $unset
➢ Array
$, $addToSet, $pop, $pullAll, $pull, $pushAll, $push

Projection
$, $elemMatch, $slice
What is the Casbah?
➢ Casbah is a Scala toolkit for MongoDB—We use the term “toolkit” rather
than “driver”, as Casbah integrates a layer on top of the official
mongo-java-driver for better integration with Scala.
Installing & Setting up Casbah
*You should have MongoDB setup and running on your machine.
Add casbah dependencies to buid.sbt

resolvers += "Scala-tools" at
"https://oss.sonatype.org/content/groups/scala-tools"
resolvers += "Sonatype Snapshot" at
"https://oss.sonatype.org/content/repositories/releases"
libraryDependencies ++= Seq(
"org.mongodb" % "casbah_2.10" % "2.5.1"
)
Use Casbah with Scala
➢ Import the Driver
import com.mongodb.casbah.Imports._

➢ Connecting to MongoDB
Connect to default - localhost, 27017
val mongoConnection = MongoConnection()
connect to "mongodb01" host, default port
val mongoConnection = MongoConnection("mongodb01")
connect to "mongodb02" host, port 42017
val mongoConnection = MongoConnection("mongodb02", 42017)
val mongoDB = mongoConnection("casbah_test")
Connect casbah_test database with test_data collecion by chaining
val mongoColl = mongoConnection("casbah_test")("test_data")

Working with Collections
What is Salat?
➢ Salat is a bi-directional Scala case class serialization library.
➢ Salat provides fast, reliable bi-directional serialization between
Scala case classes and MongoDB's DBObject format.
➢ case classes can be used directly for storing document by
simply declaring a DAO and with the help of some annotations
Salat DAO
SalatDAOmakes it simple to start working with your case class objects.
Use it as is or as the basis for your own DAO implementation.
By extending SalatDAO, you can do the following out of box:
➢ insert and get back an Option with the id
➢ findOne and get back an Option
➢ typed to your case class
➢ find and get back a Mongo cursor typed to your class
➢ iterate, limit, skip and sort
➢ update with a query and a case class
➢ save and remove case classes
➢ Projections
➢ built-in support for child collections
What Scala types can Salat handle?
➢ case classes
➢ embedded case classes
➢ embedded case classes typed to a trait or abstract superclass annotated
with @Salat
➢ Scala enums
➢ Options
➢ Collections

Collections
➢ Maps are represented as DBObject ; all other collections turn into DBList .
Salat collection support
Salat 0.0.8-SNAPSHOT and above support the following mutable and
immutable collections:
➢ Map
➢ Lists and linked lists
➢ Seqs and indexed seqs
➢ Set
➢ Buffer
➢ Vector
Salat Unsupported types
Salat can't support any of these types right now:
➢ Nested inner classes
➢ A class typed at the top-level to a trait or an abstract superclass

Salat can't support these types because the mongo-java-driver doesn't support
Them:
➢ Any type of Map whose key is not a String
➢ any type of map whose key is a String containing . or $
Salat Supports Annotations
Salat offers the following annotations to customize serialization
behavior:
➢ @Salat to support polymorphic instances of a trait or abstract
superclass
➢ @Key to change the name of a field
➢ @Persist to serialize a value outside the case class constructor
➢ @Ignore to ignore a field in the case class constructor
➢ @EnumAs to customize the behavior of a particular enum
Salat Grater
Grater
Salat as the notion of Grater that is responsible to the de/serialization
of a case class.
This through two simple functions, let have a Grater for the type T:
➢ asDBObject(t:T) : returns a MongoDB representation of t
➢ asObject(dbo:DBObject)[T] : returns a T instance based on the
provided
Mo ngoDB content
Installing & Setting up Salat
Add salat dependencies to buid.sbt
resolvers += "Novus Release Repository" at "http://repo.novus.com/releases/"
resolvers += "Sonatype OSS Snapshots" at "
https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies ++= Seq(
"com.novus" %% "salat" % "1.9.2-SNAPSHOT"
)
References
http://docs.mongodb.org/manual/

Más contenido relacionado

La actualidad más candente

Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBMarakana Inc.
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBJustin Smestad
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-CJuio Barros
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.Oleg Shanyuk
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to ElasticsearchSperasoft
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBLee Theobald
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS Mahboob Nur
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOSgillygize
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialSteven Francia
 
Apache Any23 - Anything to Triples
Apache Any23 - Anything to TriplesApache Any23 - Anything to Triples
Apache Any23 - Anything to TriplesMichele Mostarda
 
Building your first app with mongo db
Building your first app with mongo dbBuilding your first app with mongo db
Building your first app with mongo dbMongoDB
 

La actualidad más candente (20)

MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
Learn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDBLearn Learn how to build your mobile back-end with MongoDB
Learn Learn how to build your mobile back-end with MongoDB
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongo db operations_v2
Mongo db operations_v2Mongo db operations_v2
Mongo db operations_v2
 
Web Services with Objective-C
Web Services with Objective-CWeb Services with Objective-C
Web Services with Objective-C
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.mobile in the cloud with diamonds. improved.
mobile in the cloud with diamonds. improved.
 
Introduction to Elasticsearch
Introduction to ElasticsearchIntroduction to Elasticsearch
Introduction to Elasticsearch
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS
 
Node js crash course session 5
Node js crash course   session 5Node js crash course   session 5
Node js crash course session 5
 
MongoDB
MongoDBMongoDB
MongoDB
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOS
 
Ajax xml json
Ajax xml jsonAjax xml json
Ajax xml json
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
Apache Any23 - Anything to Triples
Apache Any23 - Anything to TriplesApache Any23 - Anything to Triples
Apache Any23 - Anything to Triples
 
Building your first app with mongo db
Building your first app with mongo dbBuilding your first app with mongo db
Building your first app with mongo db
 
Mongo db
Mongo dbMongo db
Mongo db
 

Similar a Scala with mongodb

Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMohan Rathour
 
Big data technology unit 3
Big data technology unit 3Big data technology unit 3
Big data technology unit 3RojaT4
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql DatabasePrashant Gupta
 
NOSQL and MongoDB Database
NOSQL and MongoDB DatabaseNOSQL and MongoDB Database
NOSQL and MongoDB DatabaseTariqul islam
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodbMohammed Ragab
 
Mongo db transcript
Mongo db transcriptMongo db transcript
Mongo db transcriptfoliba
 
Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONDavide Mauri
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate
 
Klevis Mino: MongoDB
Klevis Mino: MongoDBKlevis Mino: MongoDB
Klevis Mino: MongoDBCarlo Vaccari
 
Software development - the java perspective
Software development - the java perspectiveSoftware development - the java perspective
Software development - the java perspectiveAlin Pandichi
 
Mongo presentation conf
Mongo presentation confMongo presentation conf
Mongo presentation confShridhar Joshi
 
No SQL - MongoDB
No SQL - MongoDBNo SQL - MongoDB
No SQL - MongoDBMirza Asif
 
Introduction to Cosmos DB Presentation.pptx
Introduction to Cosmos DB Presentation.pptxIntroduction to Cosmos DB Presentation.pptx
Introduction to Cosmos DB Presentation.pptxKnoldus Inc.
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App ArchitectureCorey Butler
 
nosql [Autosaved].pptx
nosql [Autosaved].pptxnosql [Autosaved].pptx
nosql [Autosaved].pptxIndrani Sen
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introductionsethfloydjr
 

Similar a Scala with mongodb (20)

Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
 
Big data technology unit 3
Big data technology unit 3Big data technology unit 3
Big data technology unit 3
 
Mongodb - NoSql Database
Mongodb - NoSql DatabaseMongodb - NoSql Database
Mongodb - NoSql Database
 
Rails meets no sql
Rails meets no sqlRails meets no sql
Rails meets no sql
 
Mongo db
Mongo dbMongo db
Mongo db
 
NOSQL and MongoDB Database
NOSQL and MongoDB DatabaseNOSQL and MongoDB Database
NOSQL and MongoDB Database
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
Mongo db transcript
Mongo db transcriptMongo db transcript
Mongo db transcript
 
MongoDB
MongoDBMongoDB
MongoDB
 
Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSON
 
Kalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB TutorialsKalp Corporate MongoDB Tutorials
Kalp Corporate MongoDB Tutorials
 
Klevis Mino: MongoDB
Klevis Mino: MongoDBKlevis Mino: MongoDB
Klevis Mino: MongoDB
 
No sql databases
No sql databasesNo sql databases
No sql databases
 
Software development - the java perspective
Software development - the java perspectiveSoftware development - the java perspective
Software development - the java perspective
 
Mongo presentation conf
Mongo presentation confMongo presentation conf
Mongo presentation conf
 
No SQL - MongoDB
No SQL - MongoDBNo SQL - MongoDB
No SQL - MongoDB
 
Introduction to Cosmos DB Presentation.pptx
Introduction to Cosmos DB Presentation.pptxIntroduction to Cosmos DB Presentation.pptx
Introduction to Cosmos DB Presentation.pptx
 
JS App Architecture
JS App ArchitectureJS App Architecture
JS App Architecture
 
nosql [Autosaved].pptx
nosql [Autosaved].pptxnosql [Autosaved].pptx
nosql [Autosaved].pptx
 
MongoDB - An Introduction
MongoDB - An IntroductionMongoDB - An Introduction
MongoDB - An Introduction
 

Más de Knoldus Inc.

Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxKnoldus Inc.
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxKnoldus Inc.
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxKnoldus Inc.
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxKnoldus Inc.
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationKnoldus Inc.
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationKnoldus Inc.
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIsKnoldus Inc.
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II PresentationKnoldus Inc.
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAKnoldus Inc.
 
Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Knoldus Inc.
 
Azure Databricks (For Data Analytics).pptx
Azure Databricks (For Data Analytics).pptxAzure Databricks (For Data Analytics).pptx
Azure Databricks (For Data Analytics).pptxKnoldus Inc.
 
The Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and KotlinThe Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and KotlinKnoldus Inc.
 
Data Engineering with Databricks Presentation
Data Engineering with Databricks PresentationData Engineering with Databricks Presentation
Data Engineering with Databricks PresentationKnoldus Inc.
 
Databricks for MLOps Presentation (AI/ML)
Databricks for MLOps Presentation (AI/ML)Databricks for MLOps Presentation (AI/ML)
Databricks for MLOps Presentation (AI/ML)Knoldus Inc.
 
NoOps - (Automate Ops) Presentation.pptx
NoOps - (Automate Ops) Presentation.pptxNoOps - (Automate Ops) Presentation.pptx
NoOps - (Automate Ops) Presentation.pptxKnoldus Inc.
 
Mastering Distributed Performance Testing
Mastering Distributed Performance TestingMastering Distributed Performance Testing
Mastering Distributed Performance TestingKnoldus Inc.
 
MLops on Vertex AI Presentation (AI/ML).pptx
MLops on Vertex AI Presentation (AI/ML).pptxMLops on Vertex AI Presentation (AI/ML).pptx
MLops on Vertex AI Presentation (AI/ML).pptxKnoldus Inc.
 
Introduction to Ansible Tower Presentation
Introduction to Ansible Tower PresentationIntroduction to Ansible Tower Presentation
Introduction to Ansible Tower PresentationKnoldus Inc.
 
CQRS with dot net services presentation.
CQRS with dot net services presentation.CQRS with dot net services presentation.
CQRS with dot net services presentation.Knoldus Inc.
 

Más de Knoldus Inc. (20)

Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRA
 
Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)
 
Azure Databricks (For Data Analytics).pptx
Azure Databricks (For Data Analytics).pptxAzure Databricks (For Data Analytics).pptx
Azure Databricks (For Data Analytics).pptx
 
The Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and KotlinThe Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and Kotlin
 
Data Engineering with Databricks Presentation
Data Engineering with Databricks PresentationData Engineering with Databricks Presentation
Data Engineering with Databricks Presentation
 
Databricks for MLOps Presentation (AI/ML)
Databricks for MLOps Presentation (AI/ML)Databricks for MLOps Presentation (AI/ML)
Databricks for MLOps Presentation (AI/ML)
 
NoOps - (Automate Ops) Presentation.pptx
NoOps - (Automate Ops) Presentation.pptxNoOps - (Automate Ops) Presentation.pptx
NoOps - (Automate Ops) Presentation.pptx
 
Mastering Distributed Performance Testing
Mastering Distributed Performance TestingMastering Distributed Performance Testing
Mastering Distributed Performance Testing
 
MLops on Vertex AI Presentation (AI/ML).pptx
MLops on Vertex AI Presentation (AI/ML).pptxMLops on Vertex AI Presentation (AI/ML).pptx
MLops on Vertex AI Presentation (AI/ML).pptx
 
Introduction to Ansible Tower Presentation
Introduction to Ansible Tower PresentationIntroduction to Ansible Tower Presentation
Introduction to Ansible Tower Presentation
 
CQRS with dot net services presentation.
CQRS with dot net services presentation.CQRS with dot net services presentation.
CQRS with dot net services presentation.
 

Último

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Último (20)

New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Scala with mongodb

  • 1. Scala with MongoDB Abdhesh Kumar Email: abdhesh@knoldus.com Twitter:@abdheshkumar90
  • 2. Agenda 1. What is MongoDB? 2. Why we use MongoDB? 3. What are the MongoDB Terminologies? 4. How to Install and Use MonogDB? 5. What are the Operators of MongoDB? 6. What is Casbah? 7. What is Salat?
  • 3. What is MongoDB? ➢ MongoDB is a document-oriented database management system designed for performance, horizontal scalability, high availability,open source NoSQL database(Schemaless or Non-relational) ,And advanced queryability. ➢ MongoDB is a document-based database system, and as a result, all records, or data, in MongoDB are documents.
  • 4. Why we use MongoDB? Document Oriented ➢ Documents (objects) map nicely to programming language data types. ➢ Dynamically-typed (schemaless) for easy schema evolution. ➢ No joins and no transactions for high performance and easy scalability High Performance ➢ No joins and no transactions makes reads and writes fast ➢ Indexes can include keys from embedded documents and arrays. ➢ Optional asynchronous writes .
  • 5. High Availability ➢Replicated servers with automatic master failover. Easy Scalability ➢ Automatic sharding distributes collection data across machines. ➢Reads and writes are distributed over shards Flexibility ➢MongoDB stores data in JSON documents (which we serialize to BSON).
  • 6. Indexing ➢ MongoDB supports generic secondary indexes, allowing a variety of fast queries,and provides unique, compound, and geospatial indexing capabilities as well. Fixed-size collections ➢ Capped collections are fixed in size and are useful for certain types of data, such as logs. ➢ Real time aggregation ➢ Rich query capabilities ➢ Geospatial features ➢ Flexible schema
  • 7. MongoDB Terminologies Sql Terms/Concepts MongoDB Terms/Concepts database database table collection index index row Document or *BSON document column Field or BSON field join *Embedding and linking Primary key _id Group by aggregation
  • 8. MongoDB Terms/Concepts Documents: ➢ The concept of a document: an ordered set of keys with associated values. ➢ documents are represented as objects: {"greeting" : "Hello, world!"} Collections: ➢ A collection is a group of documents.
  • 9. Embedding: ➢ “Embedding is the nesting of objects and arrays inside a BSON document” Linking: ➢ “Links are references between documents” Aggregation: ➢ The MongoDB aggregation framework provides a means to calculate aggregated values without having to use map-reduce. ➢ If you’re familiar with SQL, the aggregation framework provides similar functionality to GROUP BY and related SQL operators as well as simple forms of “self joins.” Additionally, the aggregation framework provides projection capabilities to reshape the returned data.
  • 10. What is JSON? ➢ JSON (JavaScript Object Notation) is a lightweight data-interchange format. ➢ JSON is built on two structures: 1. A collection of name/value pairs. ex.object, record, struct, dictionary, hash table, keyed list, or associative array 2. An ordered list of values. ex. array, vector, list, or sequence
  • 11. { "_id" : 1, "name" : { "first" : "Rohan", "last" : "Singh" }, "contributes" : [ "TypeSafe", "Knoldus" ], "awards" : [ { "award" : "Play Framework Expert", "year" : 2012, "by" : "TypeSafe" }, { "award" : "Scala Expert", "year" : 2013, "by" : "Knoldus" } ] }
  • 12. What is BSON? ➢ BSON is a binary-encoded serialization of JSON-like document. ➢ BSON supports the embedding of documents and arrays within other documents and arrays. ➢ MongoDB uses BSON as the data storage and network transfer format for “documets”.
  • 13. Install MongoDB $ wget http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.0.6.tgz $ tar -zxvf mongodb-osx-x86_64-2.0.6.tgz $ sudo mkdir -p /data/db $ sudo chown `id -u` /data/db
  • 14. Starting MonDB and Mongo Shell ➢ $ ./bin/mongod ➢ $ mongo MongoDB shell version: 2.4.1 connecting to: test >
  • 15. MongoDB Operators Query Selectors: ➢ Comparison $all, $gt, $gte, $in, $lt, $lte, $ne, $nin ➢ Logical $and, $or, $nor, $not ➢ Element $exists, $mod, $type ➢ JavaScript $regix, $where
  • 16. ➢ Array $elemMatch,$size Update ➢ Fields $inc, $set, $unset ➢ Array $, $addToSet, $pop, $pullAll, $pull, $pushAll, $push Projection $, $elemMatch, $slice
  • 17. What is the Casbah? ➢ Casbah is a Scala toolkit for MongoDB—We use the term “toolkit” rather than “driver”, as Casbah integrates a layer on top of the official mongo-java-driver for better integration with Scala.
  • 18. Installing & Setting up Casbah *You should have MongoDB setup and running on your machine. Add casbah dependencies to buid.sbt resolvers += "Scala-tools" at "https://oss.sonatype.org/content/groups/scala-tools" resolvers += "Sonatype Snapshot" at "https://oss.sonatype.org/content/repositories/releases" libraryDependencies ++= Seq( "org.mongodb" % "casbah_2.10" % "2.5.1" )
  • 19. Use Casbah with Scala ➢ Import the Driver import com.mongodb.casbah.Imports._ ➢ Connecting to MongoDB Connect to default - localhost, 27017 val mongoConnection = MongoConnection() connect to "mongodb01" host, default port val mongoConnection = MongoConnection("mongodb01") connect to "mongodb02" host, port 42017 val mongoConnection = MongoConnection("mongodb02", 42017)
  • 20. val mongoDB = mongoConnection("casbah_test") Connect casbah_test database with test_data collecion by chaining val mongoColl = mongoConnection("casbah_test")("test_data") Working with Collections
  • 21. What is Salat? ➢ Salat is a bi-directional Scala case class serialization library. ➢ Salat provides fast, reliable bi-directional serialization between Scala case classes and MongoDB's DBObject format. ➢ case classes can be used directly for storing document by simply declaring a DAO and with the help of some annotations
  • 22. Salat DAO SalatDAOmakes it simple to start working with your case class objects. Use it as is or as the basis for your own DAO implementation. By extending SalatDAO, you can do the following out of box: ➢ insert and get back an Option with the id ➢ findOne and get back an Option ➢ typed to your case class ➢ find and get back a Mongo cursor typed to your class ➢ iterate, limit, skip and sort ➢ update with a query and a case class ➢ save and remove case classes ➢ Projections ➢ built-in support for child collections
  • 23. What Scala types can Salat handle? ➢ case classes ➢ embedded case classes ➢ embedded case classes typed to a trait or abstract superclass annotated with @Salat ➢ Scala enums ➢ Options ➢ Collections Collections ➢ Maps are represented as DBObject ; all other collections turn into DBList .
  • 24. Salat collection support Salat 0.0.8-SNAPSHOT and above support the following mutable and immutable collections: ➢ Map ➢ Lists and linked lists ➢ Seqs and indexed seqs ➢ Set ➢ Buffer ➢ Vector
  • 25. Salat Unsupported types Salat can't support any of these types right now: ➢ Nested inner classes ➢ A class typed at the top-level to a trait or an abstract superclass Salat can't support these types because the mongo-java-driver doesn't support Them: ➢ Any type of Map whose key is not a String ➢ any type of map whose key is a String containing . or $
  • 26. Salat Supports Annotations Salat offers the following annotations to customize serialization behavior: ➢ @Salat to support polymorphic instances of a trait or abstract superclass ➢ @Key to change the name of a field ➢ @Persist to serialize a value outside the case class constructor ➢ @Ignore to ignore a field in the case class constructor ➢ @EnumAs to customize the behavior of a particular enum
  • 27. Salat Grater Grater Salat as the notion of Grater that is responsible to the de/serialization of a case class. This through two simple functions, let have a Grater for the type T: ➢ asDBObject(t:T) : returns a MongoDB representation of t ➢ asObject(dbo:DBObject)[T] : returns a T instance based on the provided Mo ngoDB content
  • 28. Installing & Setting up Salat Add salat dependencies to buid.sbt resolvers += "Novus Release Repository" at "http://repo.novus.com/releases/" resolvers += "Sonatype OSS Snapshots" at " https://oss.sonatype.org/content/repositories/snapshots" libraryDependencies ++= Seq( "com.novus" %% "salat" % "1.9.2-SNAPSHOT" )