SlideShare uma empresa Scribd logo
1 de 18
Abdhesh Kumar
abdhesh@knoldus.com
Type-Safe Mongo Query
(Rogue Query)
1. What is type-safe?
2. What is Mongo Record?
3. What is native Mongo query?
4.What is the Rogue query?
5. Installation
6. SetUp
7. Query Examples
Agenda
What is Type-safe?
-> It’s type safe meaning, for example, if you try to use an Int
where a String is expected in a function or query.
A type error is erroneous or undesirable program behaviour caused by a
discrepancy
between differing data types for the program's constants, variables, and
methods
(functions), e.g., treating an integer (int) as a floating-point number (float)
def typeSafeFunction(param: String): Unit ={....}
You can not call this function by passing any value other than String
ex. typeSafeFunction(23),typeSafeFunction(43.3434),typeSafeFunction(User)
Mongo Record
Mongo Record is ORM layer for Lift. Lift’s Record class represents
a database record(mongo collections), and MetaRecord trait
provides “static” methods for querying and updating records in a
fully expressive way.
Mongo Record...
object Student extends Student with MongoMetaRecord[Student]
class Student extends MongoRecord[Student] with ObjectIdPk[Student] {
def meta: Student.type = Student
object name extends StringField(this, 200)
object age extends IntField(this)
object address extends StringField(this, 200)
object scores extends BsonRecordListField(this, Score)
def toJson = this.asJSON
}
Mongo Record...
object Score extends Score with BsonMetaRecord[Score]
class Score extends BsonRecord[Score] {
def meta: Score.type = Score
object examtype extends StringField(this, 50)
object score extends DoubleField(this)
}
Mongo Query
1. find all documents
db.students.find()
2. find student that has age 20 years
db.students.find({age:20})
3. find students that has more than 25 years
db.students.find({age:{"$gte":25}})
4. find students that has more than 40% in quiz
db.students.find({"scores":{"$elemMatch"
{"score":"$gt":40},"examtype":"quiz"}}})
Scala Query Againts Mongodb
Lift’s MongoMetaRecord trait provides a findAll() method that lets you
pass in a query as a JSON object (MongoDB queries are in fact JSON
objects), returning a list of records.
For example, using lift’s JsonDSL, we can do:
Student.findAll(
(Student.name.name -> "Bao Ziglar") ~ (Student.age.name ->( “$gt”->25)))
which is equivalent to
Student.findAll("{ name : “Bao Ziglar”, age : { $gt : 25 } }")
BUT
This would also run by mongo server
Student.findAll((Student.name.name -> "Bao Ziglar") ~ (Student.age.name -> “Farji25”))
It's not a valid query and it happily executes for you, returning nothing, never informing you
that the age field is not a String but a Int representing the age of the Student.
Typesafe Query
->There should be someting here that enforce to use query in typesafe sense
-> Scala compiler should detected field type againts records, fields, conditions and
Operands
Student.where(_.name eqs “studentName”).and(_.age eqs "Farji25").fetch
It through the scala error type mismatch; found : String("Farji25") required: Int
Mongo would allow that query and fail to find results at runtime, but Rogue enables
Scala to reject the query at compile time.
Rogue Query(Typesafe query)
-> Rogue is a type-safe internal Scala DSL for constructing and
executing find and modify commands against MongoDB in the
Lift web framework.
-> It is fully expressive with respect to the basic options provided by
MongoDB's native query language, but in a type-safe manner
-> Rogue was initially developed by Foursquare Labs for internal
use nearly all of the MongoDB queries in foursquare's code base
go through this library.
Rogue Query(Typesafe query)...
The Rogue query (typesafe query) enforces the following
Constraints:
->The fields must actually belong to the record
(e.g., age is a field on the Student record)
->The field type must match the operand type
(e.g., age is an IntField)
-> The operator must make sense for the field type
(e.g., scores is a MongoListField[String])
->The value specified in the query clause is the same type as the field
type (or is appropriate for the operator)
Installation
val rogueField = "com.foursquare" %% "rogue­field" % "2.2.0" intransitive()
val rogueCore = "com.foursquare" %% "rogue­core" % "2.2.0" intransitive()
val rogueLift = "com.foursquare" %% "rogue­lift" % "2.2.0" intransitive()
val rogueIndex = "com.foursquare" %% "rogue­index" % "2.2.0" intransitive()
val liftMongoRecord = "net.liftweb" %% "lift­mongodb­record" % "2.4"
SetUp and Typesafe query
Import package:
import com.foursquare.rogue.LiftRogue._
Typesafe query:
Student.where(_.name eqs stdName).and(_.age eqs 25).fetch
Student.where(_.name eqs stdName).
and(_.scores elemMatch (_.score gte 25, _.examtype eqs "quiz")).fetch
Rogue Query
Import package:
import com.foursquare.rogue.LiftRogue._
Typesafe query:
Student.where(_.name eqs stdName).and(_.age eqs 25).fetch
equivalent to:
db.students.find({ "name" : "stdName" , "age" : 25})
Student.where(_.name eqs stdName).and(_.scores elemMatch (_.score gte
25, _.examtype eqs "quiz")).fetch
equivalent to:
db.students.find({ "name" : "stdName" , "scores" : { "$elemMatch" :
{ "examtype" : "quiz" , "score" : { "$gte" : 25.0}}}})
Rogue Query..
Student.where(_.name matches Pattern.compile(Pattern.quote(stdName),
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE)).fetch
Equivalent :
db.students.find({ "name" : { "$regex" : "QstdNameE" , "$options" : "im"}})
Rogue support.
Type safe rogue support all mongodb operators:
Like. Eqs, neq,lt,gt,in,nin,exists,startsWith, regex,all, in, size, contains, at
,BsonRecordField subfield queries
References
http://engineering.foursquare.com/2011/01/21/rogue-a-type-safe-scala-dsl-for-que
https://github.com/foursquare/rogue
Thanks

Mais conteúdo relacionado

Semelhante a Type-Safe MongoDB query (Lift Rogue query)

Introduction NullPointerException is a RuntimeException In.pdf
Introduction NullPointerException is a RuntimeException  In.pdfIntroduction NullPointerException is a RuntimeException  In.pdf
Introduction NullPointerException is a RuntimeException In.pdf
adinathknit
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
mport java.io.; class Student { int rollno; String name; .pdf
mport java.io.; class Student { int rollno; String name; .pdfmport java.io.; class Student { int rollno; String name; .pdf
mport java.io.; class Student { int rollno; String name; .pdf
aryan9007
 
The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2
Coursetro Com
 

Semelhante a Type-Safe MongoDB query (Lift Rogue query) (20)

From android/java to swift (3)
From android/java to swift (3)From android/java to swift (3)
From android/java to swift (3)
 
Mutation Testing: Testing your tests
Mutation Testing: Testing your testsMutation Testing: Testing your tests
Mutation Testing: Testing your tests
 
Introduction NullPointerException is a RuntimeException In.pdf
Introduction NullPointerException is a RuntimeException  In.pdfIntroduction NullPointerException is a RuntimeException  In.pdf
Introduction NullPointerException is a RuntimeException In.pdf
 
core java
 core java core java
core java
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
mport java.io.; class Student { int rollno; String name; .pdf
mport java.io.; class Student { int rollno; String name; .pdfmport java.io.; class Student { int rollno; String name; .pdf
mport java.io.; class Student { int rollno; String name; .pdf
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
 
Computational Problem Solving 016 (1).pptx
Computational Problem Solving 016 (1).pptxComputational Problem Solving 016 (1).pptx
Computational Problem Solving 016 (1).pptx
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. NagpurCore & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
 
Computational Problem Solving 004 (1).pptx (1).pdf
Computational Problem Solving 004 (1).pptx (1).pdfComputational Problem Solving 004 (1).pptx (1).pdf
Computational Problem Solving 004 (1).pptx (1).pdf
 
Improving Correctness with Types
Improving Correctness with TypesImproving Correctness with Types
Improving Correctness with Types
 
Big Brother helps you
Big Brother helps youBig Brother helps you
Big Brother helps you
 
“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes“Insulin” for Scala’s Syntactic Diabetes
“Insulin” for Scala’s Syntactic Diabetes
 
The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2The Ultimate FREE Java Course Part 2
The Ultimate FREE Java Course Part 2
 
{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}{"JSON, Swift and Type Safety" : "It's a wrap"}
{"JSON, Swift and Type Safety" : "It's a wrap"}
 
More Stored Procedures and MUMPS for DivConq
More Stored Procedures and  MUMPS for DivConqMore Stored Procedures and  MUMPS for DivConq
More Stored Procedures and MUMPS for DivConq
 
Variables and Data Types
Variables and Data TypesVariables and Data Types
Variables and Data Types
 
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasks
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasksSearching for AI - Leveraging Solr for classic Artificial Intelligence tasks
Searching for AI - Leveraging Solr for classic Artificial Intelligence tasks
 

Mais de Knoldus Inc.

Mais de Knoldus Inc. (20)

Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
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
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

Type-Safe MongoDB query (Lift Rogue query)

  • 2. 1. What is type-safe? 2. What is Mongo Record? 3. What is native Mongo query? 4.What is the Rogue query? 5. Installation 6. SetUp 7. Query Examples Agenda
  • 3. What is Type-safe? -> It’s type safe meaning, for example, if you try to use an Int where a String is expected in a function or query. A type error is erroneous or undesirable program behaviour caused by a discrepancy between differing data types for the program's constants, variables, and methods (functions), e.g., treating an integer (int) as a floating-point number (float) def typeSafeFunction(param: String): Unit ={....} You can not call this function by passing any value other than String ex. typeSafeFunction(23),typeSafeFunction(43.3434),typeSafeFunction(User)
  • 4. Mongo Record Mongo Record is ORM layer for Lift. Lift’s Record class represents a database record(mongo collections), and MetaRecord trait provides “static” methods for querying and updating records in a fully expressive way.
  • 5. Mongo Record... object Student extends Student with MongoMetaRecord[Student] class Student extends MongoRecord[Student] with ObjectIdPk[Student] { def meta: Student.type = Student object name extends StringField(this, 200) object age extends IntField(this) object address extends StringField(this, 200) object scores extends BsonRecordListField(this, Score) def toJson = this.asJSON }
  • 6. Mongo Record... object Score extends Score with BsonMetaRecord[Score] class Score extends BsonRecord[Score] { def meta: Score.type = Score object examtype extends StringField(this, 50) object score extends DoubleField(this) }
  • 7. Mongo Query 1. find all documents db.students.find() 2. find student that has age 20 years db.students.find({age:20}) 3. find students that has more than 25 years db.students.find({age:{"$gte":25}}) 4. find students that has more than 40% in quiz db.students.find({"scores":{"$elemMatch" {"score":"$gt":40},"examtype":"quiz"}}})
  • 8. Scala Query Againts Mongodb Lift’s MongoMetaRecord trait provides a findAll() method that lets you pass in a query as a JSON object (MongoDB queries are in fact JSON objects), returning a list of records. For example, using lift’s JsonDSL, we can do: Student.findAll( (Student.name.name -> "Bao Ziglar") ~ (Student.age.name ->( “$gt”->25))) which is equivalent to Student.findAll("{ name : “Bao Ziglar”, age : { $gt : 25 } }") BUT This would also run by mongo server Student.findAll((Student.name.name -> "Bao Ziglar") ~ (Student.age.name -> “Farji25”)) It's not a valid query and it happily executes for you, returning nothing, never informing you that the age field is not a String but a Int representing the age of the Student.
  • 9. Typesafe Query ->There should be someting here that enforce to use query in typesafe sense -> Scala compiler should detected field type againts records, fields, conditions and Operands Student.where(_.name eqs “studentName”).and(_.age eqs "Farji25").fetch It through the scala error type mismatch; found : String("Farji25") required: Int Mongo would allow that query and fail to find results at runtime, but Rogue enables Scala to reject the query at compile time.
  • 10. Rogue Query(Typesafe query) -> Rogue is a type-safe internal Scala DSL for constructing and executing find and modify commands against MongoDB in the Lift web framework. -> It is fully expressive with respect to the basic options provided by MongoDB's native query language, but in a type-safe manner -> Rogue was initially developed by Foursquare Labs for internal use nearly all of the MongoDB queries in foursquare's code base go through this library.
  • 11. Rogue Query(Typesafe query)... The Rogue query (typesafe query) enforces the following Constraints: ->The fields must actually belong to the record (e.g., age is a field on the Student record) ->The field type must match the operand type (e.g., age is an IntField) -> The operator must make sense for the field type (e.g., scores is a MongoListField[String]) ->The value specified in the query clause is the same type as the field type (or is appropriate for the operator)
  • 12. Installation val rogueField = "com.foursquare" %% "rogue­field" % "2.2.0" intransitive() val rogueCore = "com.foursquare" %% "rogue­core" % "2.2.0" intransitive() val rogueLift = "com.foursquare" %% "rogue­lift" % "2.2.0" intransitive() val rogueIndex = "com.foursquare" %% "rogue­index" % "2.2.0" intransitive() val liftMongoRecord = "net.liftweb" %% "lift­mongodb­record" % "2.4"
  • 13. SetUp and Typesafe query Import package: import com.foursquare.rogue.LiftRogue._ Typesafe query: Student.where(_.name eqs stdName).and(_.age eqs 25).fetch Student.where(_.name eqs stdName). and(_.scores elemMatch (_.score gte 25, _.examtype eqs "quiz")).fetch
  • 14. Rogue Query Import package: import com.foursquare.rogue.LiftRogue._ Typesafe query: Student.where(_.name eqs stdName).and(_.age eqs 25).fetch equivalent to: db.students.find({ "name" : "stdName" , "age" : 25}) Student.where(_.name eqs stdName).and(_.scores elemMatch (_.score gte 25, _.examtype eqs "quiz")).fetch equivalent to: db.students.find({ "name" : "stdName" , "scores" : { "$elemMatch" : { "examtype" : "quiz" , "score" : { "$gte" : 25.0}}}})
  • 15. Rogue Query.. Student.where(_.name matches Pattern.compile(Pattern.quote(stdName), Pattern.CASE_INSENSITIVE | Pattern.MULTILINE)).fetch Equivalent : db.students.find({ "name" : { "$regex" : "QstdNameE" , "$options" : "im"}})
  • 16. Rogue support. Type safe rogue support all mongodb operators: Like. Eqs, neq,lt,gt,in,nin,exists,startsWith, regex,all, in, size, contains, at ,BsonRecordField subfield queries