SlideShare a Scribd company logo
MongoDB For C++
                           Developers
                           { author: “Ynon Perek” }




Saturday, February 2, 13
Whoami




                      Ynon Perek

                      http://ynonperek.com

                      ynon@ynonperek.com




Saturday, February 2, 13
Agenda



                                Mongo Is Awesome

                                CRUD Operations

                                The Driver

                                Coding Time




Saturday, February 2, 13
Mongo Is Awesome



                  Data Store for
                  JSON Objects




Saturday, February 2, 13
Mongo Is Awesome



                  Data Store for
                  JSON Objects


          {
                “Name” : “Rose Tyler”
          }




Saturday, February 2, 13
JSON Objects


                      A JSON Object is a
                      collection of key/
                      value pairs          {
                                             "name"       : "Rose Tyler",
                      Keys are simple        "race"       : "Human",
                      strings                "body parts" : [ "head", "legs"]
                                           }
                      Values can be:
                      Numbers, Strings,
                      Arrays, Other
                      Objects, and more




Saturday, February 2, 13
It’s A Document Oriented Data
                  Store




Saturday, February 2, 13
It don’t do joins




Saturday, February 2, 13
It don’t do transactions




Saturday, February 2, 13
Keeping It Simple




                      Document Oriented

                      No Transactions

                      No Joins




Saturday, February 2, 13
Application Architecture




                             APP            DB




Saturday, February 2, 13
Application Architecture




                                                  DB

                             APP            DB



                                                  DB


Saturday, February 2, 13
What Can Mongo Do For You




                      Create and store objects

                      Arrange them in collections

                      Retrieve them later




Saturday, February 2, 13
Q&A




Saturday, February 2, 13
CRUD Operations
                           Create, Read, Update and Destroy Data


Saturday, February 2, 13
Mongo CRUD



                      Create   is called insert

                      Read     is called find

                      Update is called update

                      Destroy is called remove




Saturday, February 2, 13
Mongo CRUD



                      From a developer’s perspective, MongoDB operations are
                      the same through the driver and through the console

                      In both cases, operations look like function calls or
                      method invocations

                      We’ll use mongo shell for the rest of this chapter




Saturday, February 2, 13
Inserting Data




                      Use the command insert or save to insert a new object

                      db.collection.insert( obj );

                      db.collection.insert( array );




Saturday, February 2, 13
Inserting Data




                      Inserting to a new collection creates the collection

                      Inserting an object with an _id key, it is used as the
                      object’s id (and must be unique).




Saturday, February 2, 13
Demo: Insert




Saturday, February 2, 13
Reading Data


                      find and findOne perform read operations

                      Both take a query

                      find returns    a cursor

                      findOne returns an object           Optional: Fields to
                                                                fetch

                      db.collection.find( <query>, <projection> )




Saturday, February 2, 13
Query Document



                      An empty (or missing) query document returns
                      everything

                      db.collection.find({})

                      db.collection.find()




Saturday, February 2, 13
Query Document



                      Each key/value pair in the query document imposes a
                      condition on the results (objects that match).

                      db.movies.find({ “genre” : “indie” });

                      db.books.find({“pages” : { “$gt” : 100 }});




Saturday, February 2, 13
Query Document

                                                         Query Object

                      Each key/value pair in the query document imposes a
                      condition on the results (objects that match).

                      db.movies.find({ “genre” : “indie” });

                      db.books.find({“pages” : { “$gt” : 100 }});




Saturday, February 2, 13
Query Document


                      A compound query means a logical AND on the
                      conditions.

                      db.inventory.find(
                        {
                            “type” : “snacks”,
                            “available” : { “$lt” : 10 }
                        });




Saturday, February 2, 13
Quiz: What Is Returned


                                           from      alterego   publisher

                                                     Bruce
                      {                    Earth                DC
                                                     Wayne
                           “publisher” :
                           “DC”
                      }                              Peter
                                           Earth                Marvel
                                                     Parker

                                           Krypton   Clark Kent DC



Saturday, February 2, 13
Quiz: What Is Returned


                                           from      alterego   publisher

                      {                              Bruce
                           “publisher” :   Earth                DC
                                                     Wayne
                           “DC”,
                           “from” :
                           “Earth”                   Peter
                                           Earth                Marvel
                      }                              Parker

                                           Krypton   Clark Kent DC



Saturday, February 2, 13
Resources




                      Queries Cheat Sheet
                      http://www.10gen.com/sites/default/files/downloads/
                      mongodb_qrc_queries.pdf




Saturday, February 2, 13
Demo: Query




Saturday, February 2, 13
Update



                      Update operations modify existing data in the DB

                      Mongo supports two update commands:
                      update() and save()

                      Update is the more general (and complex)




Saturday, February 2, 13
Update




                      The general form for update is:


                      db.collection.update(
                        <query>, <update>, <options> )



               Which Entries                   What to do with
               to update                       them

Saturday, February 2, 13
Update



                      The second argument to update() is an operator object

                      It tells update what to do with the data

                      Some keys you can use: “$set”, “$inc” “$push”,
                      “$pushAll”, “$addToSet”, “$pop”, “$pull”, “$pullAll”




Saturday, February 2, 13
Update: set


                      $set modifies a value or add a new value

                      Example:

                      db.posts.update(
                         { title: “Why Is Your Cat Unhappy” },
                         { $set : { “archived” : true } }
                      );




Saturday, February 2, 13
Quiz: $set



                      What happens here ?

                      db.cats.update(
                         { color: “white” },
                         { “$set” : { “owners” : [“John”, “Jim”] } }
                      );




Saturday, February 2, 13
Quiz: $set


                      Update owners array of the first cat with white color

                      If you want to update all objects, use multi

                      db.cats.update(
                         { color: “white” },
                         { “$set” : { “owners” : [“John”, “Jim”] } }
                         { multi : true }
                      );




Saturday, February 2, 13
Deleting Data

                      remove() deletes objects from a collection

                      Takes a query and possibly a <justOne> arguments

                      Examples:

                      db.posts.remove({ “author” : “Father Angelo” })

                      db.music.remove({ “genres” : “pop” })

                      db.posts.remove({ “tags” : “funny” }, 1 );




Saturday, February 2, 13
Q&A




Saturday, February 2, 13
The Driver




                      Hello C++ Mongo

                      C++ Objects

                      Coding Time




Saturday, February 2, 13
Hello Mongo

               #include <iostream>
               #include "client/dbclient.h"

               using namespace mongo; 

               int main() {
                 try {
                   DBClientConnection c;
                   c.connect("localhost");

                      cout << "connected ok" << endl;
                    } catch( DBException &e ) {
                      cout << "caught " << e.what() << endl;
                    }
                    return 0;
               }



Saturday, February 2, 13
Insert Data


              BSONObjBuilder b;
              b.append("name", "John");
              b.append("age", 19);
               
              BSONObj p1 = b.obj();
              c.insert("test.people", p1);




Saturday, February 2, 13
Query Data


              void printIfAge(DBClientConnection&c, int age) {
                auto_ptr<DBClientCursor> cursor =
                  c.query("tutorial.persons", QUERY( "age" << age ) );


                   while( cursor->more() ) {
                     BSONObj p = cursor->next();
                     cout << p.getStringField("name") << endl;
                   }
              }




Saturday, February 2, 13
Update Data




              db.update( "tutorial.persons" ,
                         BSON( "name" << "Joe" << "age" << 33 ),
                         BSON( "$inc" << BSON( "visits" << 1 ) ) );




Saturday, February 2, 13
Delete Data



              db.remove("tutorial.persons",
                        QUERY("age" << 19));




Saturday, February 2, 13
C++ Objects


                      DBClientConnection
                      represents a
                      connection
                                            DBClientConnection c;
                      Methods:              c.connect("localhost");

                           connect, auth

                           insert, query,
                           update, remove




Saturday, February 2, 13
C++ Objects


                      Query
                      data object
                      represents a
                      query            QUERY( "age"    << 33      <<
                                              "school" << "UCLA" ).
                                            sort("name");
                      Methods:
                                       QUERY( "age" << GT << 30 << LT << 50 )
                           sort

                      Create with
                      macro QUERY




Saturday, February 2, 13
C++ Objects

                      DBClientCursor
                      Returned from
                      query()
                                       auto_ptr<DBClientCursor> cursor =
                      Methods:                c.query("tutorial.persons",
                                              BSONObj());
                           more()      while( cursor->more() )
                                             cout << cursor->next().toString();
                           next()

                      Create with
                      auto_ptr




Saturday, February 2, 13
Coding Time



                      Mongo Score Board:
                      https://github.com/
                      ynonp/mongo-score

                      MoChat:
                      https://github.com/
                      ynonp/mochat




Saturday, February 2, 13
Thanks For Listening



                      Ynon Perek

                      Slides at:
                      ynonperek.com

                      Talk to me at:
                      ynon@ynonperek.com




Saturday, February 2, 13

More Related Content

What's hot (20)

Linux kernel memory allocators
Linux kernel memory allocatorsLinux kernel memory allocators
Linux kernel memory allocators
Hao-Ran Liu
 
Adaptive Query Execution: Speeding Up Spark SQL at Runtime
Adaptive Query Execution: Speeding Up Spark SQL at RuntimeAdaptive Query Execution: Speeding Up Spark SQL at Runtime
Adaptive Query Execution: Speeding Up Spark SQL at Runtime
Databricks
 
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
Edureka!
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
Brendan Gregg
 
인공지능 방법론 - 딥러닝 이해하기
인공지능 방법론 - 딥러닝 이해하기인공지능 방법론 - 딥러닝 이해하기
인공지능 방법론 - 딥러닝 이해하기
Byoung-Hee Kim
 
Perceptron & Neural Networks
Perceptron & Neural NetworksPerceptron & Neural Networks
Perceptron & Neural Networks
NAGUR SHAREEF SHAIK
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
Kernel TLV
 
Linux Internals - Part III
Linux Internals - Part IIILinux Internals - Part III
Linux Internals - Part III
Emertxe Information Technologies Pvt Ltd
 
All about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdfAll about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdf
Altinity Ltd
 
Ingesting streaming data into Graph Database
Ingesting streaming data into Graph DatabaseIngesting streaming data into Graph Database
Ingesting streaming data into Graph Database
Guido Schmutz
 
Operating Systems - A Primer
Operating Systems - A PrimerOperating Systems - A Primer
Operating Systems - A Primer
Saumil Shah
 
MPIによる並列計算
MPIによる並列計算MPIによる並列計算
MPIによる並列計算
HPCシステムズ株式会社
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
datamantra
 
Neural networks and deep learning
Neural networks and deep learningNeural networks and deep learning
Neural networks and deep learning
Jörgen Sandig
 
Qué hace tu Asterisk cuando no miras
Qué hace tu Asterisk cuando no mirasQué hace tu Asterisk cuando no miras
Qué hace tu Asterisk cuando no miras
Elio Rojano
 
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOTricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Altinity Ltd
 
Cuda tutorial
Cuda tutorialCuda tutorial
Cuda tutorial
Mahesh Khadatare
 
Feature Engineering
Feature EngineeringFeature Engineering
Feature Engineering
HJ van Veen
 
Memory Management in Apache Spark
Memory Management in Apache SparkMemory Management in Apache Spark
Memory Management in Apache Spark
Databricks
 
An Intro to Elasticsearch and Kibana
An Intro to Elasticsearch and KibanaAn Intro to Elasticsearch and Kibana
An Intro to Elasticsearch and Kibana
ObjectRocket
 
Linux kernel memory allocators
Linux kernel memory allocatorsLinux kernel memory allocators
Linux kernel memory allocators
Hao-Ran Liu
 
Adaptive Query Execution: Speeding Up Spark SQL at Runtime
Adaptive Query Execution: Speeding Up Spark SQL at RuntimeAdaptive Query Execution: Speeding Up Spark SQL at Runtime
Adaptive Query Execution: Speeding Up Spark SQL at Runtime
Databricks
 
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
Edureka!
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
Brendan Gregg
 
인공지능 방법론 - 딥러닝 이해하기
인공지능 방법론 - 딥러닝 이해하기인공지능 방법론 - 딥러닝 이해하기
인공지능 방법론 - 딥러닝 이해하기
Byoung-Hee Kim
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
Kernel TLV
 
All about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdfAll about Zookeeper and ClickHouse Keeper.pdf
All about Zookeeper and ClickHouse Keeper.pdf
Altinity Ltd
 
Ingesting streaming data into Graph Database
Ingesting streaming data into Graph DatabaseIngesting streaming data into Graph Database
Ingesting streaming data into Graph Database
Guido Schmutz
 
Operating Systems - A Primer
Operating Systems - A PrimerOperating Systems - A Primer
Operating Systems - A Primer
Saumil Shah
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
datamantra
 
Neural networks and deep learning
Neural networks and deep learningNeural networks and deep learning
Neural networks and deep learning
Jörgen Sandig
 
Qué hace tu Asterisk cuando no miras
Qué hace tu Asterisk cuando no mirasQué hace tu Asterisk cuando no miras
Qué hace tu Asterisk cuando no miras
Elio Rojano
 
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOTricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Altinity Ltd
 
Feature Engineering
Feature EngineeringFeature Engineering
Feature Engineering
HJ van Veen
 
Memory Management in Apache Spark
Memory Management in Apache SparkMemory Management in Apache Spark
Memory Management in Apache Spark
Databricks
 
An Intro to Elasticsearch and Kibana
An Intro to Elasticsearch and KibanaAn Intro to Elasticsearch and Kibana
An Intro to Elasticsearch and Kibana
ObjectRocket
 

Viewers also liked (9)

RealTime Web with PocketIO
RealTime Web with PocketIORealTime Web with PocketIO
RealTime Web with PocketIO
Ynon Perek
 
Mongo db 시작하기
Mongo db 시작하기Mongo db 시작하기
Mongo db 시작하기
OnGameServer
 
Docker From Scratch
Docker From ScratchDocker From Scratch
Docker From Scratch
Giacomo Vacca
 
Introduction to MongoDB (from Austin Code Camp)
Introduction to MongoDB (from Austin Code Camp)Introduction to MongoDB (from Austin Code Camp)
Introduction to MongoDB (from Austin Code Camp)
Chris Edwards
 
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101
MongoDB
 
REST API 디자인 개요
REST API 디자인 개요REST API 디자인 개요
REST API 디자인 개요
nexusz99
 
닷넷프레임워크에서 Redis 사용하기
닷넷프레임워크에서 Redis 사용하기닷넷프레임워크에서 Redis 사용하기
닷넷프레임워크에서 Redis 사용하기
흥배 최
 
MongoDB for Time Series Data: Setting the Stage for Sensor Management
MongoDB for Time Series Data: Setting the Stage for Sensor ManagementMongoDB for Time Series Data: Setting the Stage for Sensor Management
MongoDB for Time Series Data: Setting the Stage for Sensor Management
MongoDB
 
MongoDB for Time Series Data Part 1: Setting the Stage for Sensor Management
MongoDB for Time Series Data Part 1: Setting the Stage for Sensor ManagementMongoDB for Time Series Data Part 1: Setting the Stage for Sensor Management
MongoDB for Time Series Data Part 1: Setting the Stage for Sensor Management
MongoDB
 
RealTime Web with PocketIO
RealTime Web with PocketIORealTime Web with PocketIO
RealTime Web with PocketIO
Ynon Perek
 
Mongo db 시작하기
Mongo db 시작하기Mongo db 시작하기
Mongo db 시작하기
OnGameServer
 
Introduction to MongoDB (from Austin Code Camp)
Introduction to MongoDB (from Austin Code Camp)Introduction to MongoDB (from Austin Code Camp)
Introduction to MongoDB (from Austin Code Camp)
Chris Edwards
 
MongoDB Administration 101
MongoDB Administration 101MongoDB Administration 101
MongoDB Administration 101
MongoDB
 
REST API 디자인 개요
REST API 디자인 개요REST API 디자인 개요
REST API 디자인 개요
nexusz99
 
닷넷프레임워크에서 Redis 사용하기
닷넷프레임워크에서 Redis 사용하기닷넷프레임워크에서 Redis 사용하기
닷넷프레임워크에서 Redis 사용하기
흥배 최
 
MongoDB for Time Series Data: Setting the Stage for Sensor Management
MongoDB for Time Series Data: Setting the Stage for Sensor ManagementMongoDB for Time Series Data: Setting the Stage for Sensor Management
MongoDB for Time Series Data: Setting the Stage for Sensor Management
MongoDB
 
MongoDB for Time Series Data Part 1: Setting the Stage for Sensor Management
MongoDB for Time Series Data Part 1: Setting the Stage for Sensor ManagementMongoDB for Time Series Data Part 1: Setting the Stage for Sensor Management
MongoDB for Time Series Data Part 1: Setting the Stage for Sensor Management
MongoDB
 
Ad

Similar to MongoDB For C++ Developers (8)

MongoDB for Perl Developers
MongoDB for Perl DevelopersMongoDB for Perl Developers
MongoDB for Perl Developers
Ynon Perek
 
Node-IL Meetup 12/2
Node-IL Meetup 12/2Node-IL Meetup 12/2
Node-IL Meetup 12/2
Ynon Perek
 
Build your own game with html5
Build your own game with html5Build your own game with html5
Build your own game with html5
Yohan Totting
 
What's new in Rails5?
What's new in Rails5?What's new in Rails5?
What's new in Rails5?
Fernand Galiana
 
Municipal Government Meets NoSQL
Municipal Government Meets NoSQLMunicipal Government Meets NoSQL
Municipal Government Meets NoSQL
MongoDB
 
Javascript in the cloud
Javascript in the cloudJavascript in the cloud
Javascript in the cloud
Mostafa Eweda
 
Symfony2 and MongoDB - MidwestPHP 2013
Symfony2 and MongoDB - MidwestPHP 2013   Symfony2 and MongoDB - MidwestPHP 2013
Symfony2 and MongoDB - MidwestPHP 2013
Pablo Godel
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
Ynon Perek
 
MongoDB for Perl Developers
MongoDB for Perl DevelopersMongoDB for Perl Developers
MongoDB for Perl Developers
Ynon Perek
 
Node-IL Meetup 12/2
Node-IL Meetup 12/2Node-IL Meetup 12/2
Node-IL Meetup 12/2
Ynon Perek
 
Build your own game with html5
Build your own game with html5Build your own game with html5
Build your own game with html5
Yohan Totting
 
Municipal Government Meets NoSQL
Municipal Government Meets NoSQLMunicipal Government Meets NoSQL
Municipal Government Meets NoSQL
MongoDB
 
Javascript in the cloud
Javascript in the cloudJavascript in the cloud
Javascript in the cloud
Mostafa Eweda
 
Symfony2 and MongoDB - MidwestPHP 2013
Symfony2 and MongoDB - MidwestPHP 2013   Symfony2 and MongoDB - MidwestPHP 2013
Symfony2 and MongoDB - MidwestPHP 2013
Pablo Godel
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
Ynon Perek
 
Ad

More from Ynon Perek (20)

Regexp
RegexpRegexp
Regexp
Ynon Perek
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
Ynon Perek
 
09 performance
09 performance09 performance
09 performance
Ynon Perek
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web Intro
Ynon Perek
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
Ynon Perek
 
Vimperl
VimperlVimperl
Vimperl
Ynon Perek
 
Syllabus
SyllabusSyllabus
Syllabus
Ynon Perek
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
Ynon Perek
 
Network
NetworkNetwork
Network
Ynon Perek
 
Architecture app
Architecture appArchitecture app
Architecture app
Ynon Perek
 
Cryptography
CryptographyCryptography
Cryptography
Ynon Perek
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
Ynon Perek
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
Ynon Perek
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
Ynon Perek
 
Accessibility
AccessibilityAccessibility
Accessibility
Ynon Perek
 
Angularjs
AngularjsAngularjs
Angularjs
Ynon Perek
 
Js memory
Js memoryJs memory
Js memory
Ynon Perek
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
Ynon Perek
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
Ynon Perek
 
09 performance
09 performance09 performance
09 performance
Ynon Perek
 
Mobile Web Intro
Mobile Web IntroMobile Web Intro
Mobile Web Intro
Ynon Perek
 
Qt multi threads
Qt multi threadsQt multi threads
Qt multi threads
Ynon Perek
 
Mobile Devices
Mobile DevicesMobile Devices
Mobile Devices
Ynon Perek
 
Architecture app
Architecture appArchitecture app
Architecture app
Ynon Perek
 
Unit Testing JavaScript Applications
Unit Testing JavaScript ApplicationsUnit Testing JavaScript Applications
Unit Testing JavaScript Applications
Ynon Perek
 
How to write easy-to-test JavaScript
How to write easy-to-test JavaScriptHow to write easy-to-test JavaScript
How to write easy-to-test JavaScript
Ynon Perek
 
Introduction to Selenium and Ruby
Introduction to Selenium and RubyIntroduction to Selenium and Ruby
Introduction to Selenium and Ruby
Ynon Perek
 
Introduction To Web Application Testing
Introduction To Web Application TestingIntroduction To Web Application Testing
Introduction To Web Application Testing
Ynon Perek
 
Qt Design Patterns
Qt Design PatternsQt Design Patterns
Qt Design Patterns
Ynon Perek
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
Ynon Perek
 

Recently uploaded (20)

Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
European Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility TestingEuropean Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility Testing
Julia Undeutsch
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Cyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptxCyber Security Legal Framework in Nepal.pptx
Cyber Security Legal Framework in Nepal.pptx
Ghimire B.R.
 
Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025Kubernetes Cloud Native Indonesia Meetup - May 2025
Kubernetes Cloud Native Indonesia Meetup - May 2025
Prasta Maha
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Measuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI SuccessMeasuring Microsoft 365 Copilot and Gen AI Success
Measuring Microsoft 365 Copilot and Gen AI Success
Nikki Chapple
 
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath InsightsUiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPath Community Berlin: Studio Tips & Tricks and UiPath Insights
UiPathCommunity
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
GDG Cloud Southlake #43: Tommy Todd: The Quantum Apocalypse: A Looming Threat...
James Anderson
 
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptxECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
ECS25 - The adventures of a Microsoft 365 Platform Owner - Website.pptx
Jasper Oosterveld
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
European Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility TestingEuropean Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility Testing
Julia Undeutsch
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Introducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRCIntroducing the OSA 3200 SP and OSA 3250 ePRC
Introducing the OSA 3200 SP and OSA 3250 ePRC
Adtran
 

MongoDB For C++ Developers

  • 1. MongoDB For C++ Developers { author: “Ynon Perek” } Saturday, February 2, 13
  • 2. Whoami Ynon Perek http://ynonperek.com [email protected] Saturday, February 2, 13
  • 3. Agenda Mongo Is Awesome CRUD Operations The Driver Coding Time Saturday, February 2, 13
  • 4. Mongo Is Awesome Data Store for JSON Objects Saturday, February 2, 13
  • 5. Mongo Is Awesome Data Store for JSON Objects { “Name” : “Rose Tyler” } Saturday, February 2, 13
  • 6. JSON Objects A JSON Object is a collection of key/ value pairs {   "name" : "Rose Tyler", Keys are simple   "race" : "Human", strings   "body parts" : [ "head", "legs"] } Values can be: Numbers, Strings, Arrays, Other Objects, and more Saturday, February 2, 13
  • 7. It’s A Document Oriented Data Store Saturday, February 2, 13
  • 8. It don’t do joins Saturday, February 2, 13
  • 9. It don’t do transactions Saturday, February 2, 13
  • 10. Keeping It Simple Document Oriented No Transactions No Joins Saturday, February 2, 13
  • 11. Application Architecture APP DB Saturday, February 2, 13
  • 12. Application Architecture DB APP DB DB Saturday, February 2, 13
  • 13. What Can Mongo Do For You Create and store objects Arrange them in collections Retrieve them later Saturday, February 2, 13
  • 15. CRUD Operations Create, Read, Update and Destroy Data Saturday, February 2, 13
  • 16. Mongo CRUD Create is called insert Read is called find Update is called update Destroy is called remove Saturday, February 2, 13
  • 17. Mongo CRUD From a developer’s perspective, MongoDB operations are the same through the driver and through the console In both cases, operations look like function calls or method invocations We’ll use mongo shell for the rest of this chapter Saturday, February 2, 13
  • 18. Inserting Data Use the command insert or save to insert a new object db.collection.insert( obj ); db.collection.insert( array ); Saturday, February 2, 13
  • 19. Inserting Data Inserting to a new collection creates the collection Inserting an object with an _id key, it is used as the object’s id (and must be unique). Saturday, February 2, 13
  • 21. Reading Data find and findOne perform read operations Both take a query find returns a cursor findOne returns an object Optional: Fields to fetch db.collection.find( <query>, <projection> ) Saturday, February 2, 13
  • 22. Query Document An empty (or missing) query document returns everything db.collection.find({}) db.collection.find() Saturday, February 2, 13
  • 23. Query Document Each key/value pair in the query document imposes a condition on the results (objects that match). db.movies.find({ “genre” : “indie” }); db.books.find({“pages” : { “$gt” : 100 }}); Saturday, February 2, 13
  • 24. Query Document Query Object Each key/value pair in the query document imposes a condition on the results (objects that match). db.movies.find({ “genre” : “indie” }); db.books.find({“pages” : { “$gt” : 100 }}); Saturday, February 2, 13
  • 25. Query Document A compound query means a logical AND on the conditions. db.inventory.find( { “type” : “snacks”, “available” : { “$lt” : 10 } }); Saturday, February 2, 13
  • 26. Quiz: What Is Returned from alterego publisher Bruce { Earth DC Wayne “publisher” : “DC” } Peter Earth Marvel Parker Krypton Clark Kent DC Saturday, February 2, 13
  • 27. Quiz: What Is Returned from alterego publisher { Bruce “publisher” : Earth DC Wayne “DC”, “from” : “Earth” Peter Earth Marvel } Parker Krypton Clark Kent DC Saturday, February 2, 13
  • 28. Resources Queries Cheat Sheet http://www.10gen.com/sites/default/files/downloads/ mongodb_qrc_queries.pdf Saturday, February 2, 13
  • 30. Update Update operations modify existing data in the DB Mongo supports two update commands: update() and save() Update is the more general (and complex) Saturday, February 2, 13
  • 31. Update The general form for update is: db.collection.update( <query>, <update>, <options> ) Which Entries What to do with to update them Saturday, February 2, 13
  • 32. Update The second argument to update() is an operator object It tells update what to do with the data Some keys you can use: “$set”, “$inc” “$push”, “$pushAll”, “$addToSet”, “$pop”, “$pull”, “$pullAll” Saturday, February 2, 13
  • 33. Update: set $set modifies a value or add a new value Example: db.posts.update( { title: “Why Is Your Cat Unhappy” }, { $set : { “archived” : true } } ); Saturday, February 2, 13
  • 34. Quiz: $set What happens here ? db.cats.update( { color: “white” }, { “$set” : { “owners” : [“John”, “Jim”] } } ); Saturday, February 2, 13
  • 35. Quiz: $set Update owners array of the first cat with white color If you want to update all objects, use multi db.cats.update( { color: “white” }, { “$set” : { “owners” : [“John”, “Jim”] } } { multi : true } ); Saturday, February 2, 13
  • 36. Deleting Data remove() deletes objects from a collection Takes a query and possibly a <justOne> arguments Examples: db.posts.remove({ “author” : “Father Angelo” }) db.music.remove({ “genres” : “pop” }) db.posts.remove({ “tags” : “funny” }, 1 ); Saturday, February 2, 13
  • 38. The Driver Hello C++ Mongo C++ Objects Coding Time Saturday, February 2, 13
  • 39. Hello Mongo #include <iostream> #include "client/dbclient.h" using namespace mongo;  int main() {   try {   DBClientConnection c;   c.connect("localhost");     cout << "connected ok" << endl;   } catch( DBException &e ) {     cout << "caught " << e.what() << endl;   }   return 0; } Saturday, February 2, 13
  • 40. Insert Data BSONObjBuilder b; b.append("name", "John"); b.append("age", 19);   BSONObj p1 = b.obj(); c.insert("test.people", p1); Saturday, February 2, 13
  • 41. Query Data void printIfAge(DBClientConnection&c, int age) {   auto_ptr<DBClientCursor> cursor =     c.query("tutorial.persons", QUERY( "age" << age ) );   while( cursor->more() ) {     BSONObj p = cursor->next();     cout << p.getStringField("name") << endl;   } } Saturday, February 2, 13
  • 42. Update Data db.update( "tutorial.persons" ,            BSON( "name" << "Joe" << "age" << 33 ),            BSON( "$inc" << BSON( "visits" << 1 ) ) ); Saturday, February 2, 13
  • 43. Delete Data db.remove("tutorial.persons", QUERY("age" << 19)); Saturday, February 2, 13
  • 44. C++ Objects DBClientConnection represents a connection DBClientConnection c; Methods: c.connect("localhost"); connect, auth insert, query, update, remove Saturday, February 2, 13
  • 45. C++ Objects Query data object represents a query QUERY( "age" << 33 << "school" << "UCLA" ). sort("name"); Methods: QUERY( "age" << GT << 30 << LT << 50 ) sort Create with macro QUERY Saturday, February 2, 13
  • 46. C++ Objects DBClientCursor Returned from query() auto_ptr<DBClientCursor> cursor = Methods: c.query("tutorial.persons", BSONObj()); more() while( cursor->more() )       cout << cursor->next().toString(); next() Create with auto_ptr Saturday, February 2, 13
  • 47. Coding Time Mongo Score Board: https://github.com/ ynonp/mongo-score MoChat: https://github.com/ ynonp/mochat Saturday, February 2, 13
  • 48. Thanks For Listening Ynon Perek Slides at: ynonperek.com Talk to me at: [email protected] Saturday, February 2, 13