mongodb efficient crud queries in - crud queries in mongodb 26 april - 11:35 am - 12:00 am at room...
TRANSCRIPT
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
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.
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)