14
Efficient CRUD queries in MongoDB 26 April - 11:35 AM - 12:00 AM at Room 209

MongoDB Efficient CRUD queries in - CRUD queries in MongoDB 26 April - 11:35 AM - 12:00 AM at Room 209. 2 { me : '@adamotonete' } Adamo Tonete ... Node Perl PHP Python Ruby Motor Scala

  • Upload
    buianh

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

Efficient CRUD queries in MongoDB

26 April - 11:35 AM - 12:00 AM at Room 209

2

{ me : '@adamotonete' }

Adamo Tonete

I've been working for Percona since late 2015 as a Senior Technical Services Engineer.I live in São Paulo/Brazil

Agenda

4

Available Drivers

● We can connect mongodb with almost all the programming languages:

Please see more on: https://docs.mongodb.com/ecosystem/drivers/community-supported-drivers/

C C++ C# Java

Node Perl PHP Python

Ruby Motor Scala Go

Erlang Delphi F# Groovy

Haskell Lua Lisp Swift

5

Python example

● In the following example we will walk through a simple python program that will connect to a replica-set and perform reads in the secondaries and writes in the primary.

6

Minimum requirements

● python 2.7;● pip (desired);● pymongo

7

Replicaset Concepts

Primary

Secondary Secondary SecondarySecondary

8

The environment

501 834 1 0 11:04 ?? 0:01.37 ./mongod --dbpath data1 --logpath data1/log1.log --fork --replSet foo

501 839 1 0 11:04 ?? 0:01.22 ./mongod --dbpath data2 --logpath data2/log2.log --fork --replSet foo --port 27018

501 843 1 0 11:04 ?? 0:01.12 ./mongod --dbpath data3 --logpath data3/log3.log --fork --replSet foo --port 27019

9

Connection

c = MongoClient('localhost:27019')

c = MongoClient('localhost:27019', replicaset : 'foo')

c = MongoClient('localhost:27019,localhost:27017', replicaset='foo', readPreference = 'secondaryPreferred')

10

Read Preference

c = MongoClient('localhost:27019,localhost:27017', replicaset='foo', readPreference = 'secondaryPreferred')

db = c.get_database('test', read_preference=ReadPreference.SECONDARY_PREFERRED )

collection = db.get_collection('foo', read_preference=ReadPreference.PRIMARY_PREFERRED)

11

Write Concern

c = MongoClient('localhost:27019,localhost:27017', replicaset='foo', readPreference='secondaryPreferred', w=1)

db.collection.Insert.({x : 1}, w=1)

12

Read/Write Concepts tags

Primary

Secondary Secondary SecondarySecondary

DC 1 DC 1

DC 1

DC 2DC 2

13

Q&A

14

Rate this session